<div dir="ltr"><div><div><div>Hi Sean,<br><br></div>A quick remark: note that let* accepts duplicate identifiers just fine (because it is defined to bind<br>them sequentially, so the last one wins).<br></div>Wouldn&#39;t that simplify your code a lot?<br>
<br></div>Stephan<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/1/1 Sean Kanaley <span dir="ltr">&lt;<a href="mailto:skanaley@gmail.com" target="_blank">skanaley@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
While I&#39;ve ultimately succeeded in having it return the correct output for a sample input, I&#39;m not positive it&#39;s correct in general and I <i>am </i>positive it&#39;s written poorly, as I don&#39;t fully understand both syntax-case and syntax objects vs. datums.  If someone could look it over and provide a more canonical version, I would be grateful.<br>

<br>Here&#39;s how the macro works:<br><br><span style="font-family:courier new,monospace">&gt; (condlet (((= 1 2) (x (princ ’a)) (y (princ ’b)))<br>            ((= 1 1) (y (princ ’c)) (x (princ ’d)))<br>            (t (x (princ ’e)) (z (princ ’f))))<br>

    (list x y z))<br><b>CD<br>(D C NIL)</b></span><br><br>Before I post the horrible racket code, I will explain the problems I&#39;m having with macros in general:<br><br>Problem 1, separate phases:  I have a remove-duplicates-by function that would be great to have globally, but it seemingly must be written locally.<br>

<br>Problem 2: You can&#39;t use a pattern variable outside of a pattern, so 
you have to syntax-ify it with #&#39;, but then you can&#39;t access the associated 
s-exp without removing the syntax.  The way to bind things to null by default is to get every id and output the obvious let statement, except ids might be repeated so you have to remove duplicates (enter problem 1).  It&#39;s remove-duplicates-BY because the removal happens by syntax-&gt;datum&#39;ing each identifier-syntax-thing since it can&#39;t appear outside of a pattern.<br>

<br>Problem 2: How to remove a portion of the macro code into a separate transformer function?  It&#39;s kind of annoying having a whole block of code relegated to cleaning up the duplicate ids inside of the let it expands into.  That would ideally be written &quot;let #,(remove-dups #&#39;(c cs...))&quot; or similar...some kind of sub-macro to handle just getting ids.  I thought that&#39;s what let-syntax or nested define syntaxes were for but I get phase errors or preposterous, very dark errors like &quot;lambda not bound&quot;.  Suddenly I prefer Haskell&#39;s <b>a is not an infinitely existential StateT (Bool -&gt; IO (StateT (Cont String) (Cont String) ())) Maybe (a1,a1&#39;), in subexpression f . g</b>.  Oh, f &lt;$&gt; g.  <b>everything checks out now!  </b>Thanks, ghci, and by the way go **** yourself you stupid Cont.<br>

<br>Anywayyyyy here is my code that works for the above example at least:<br><br><span style="font-family:courier new,monospace">(define-syntax (condlet s)<br>  (let ((remove-duplicates-by<br>         (λ (f l) (let R ((l l))<br>

                    (if (null? l)<br>                        null<br>                        (cons (car l) (R (remove* (list (car l))<br>                                                  (cdr l)<br>                                                  (λ (a b)<br>

                                                    (eq? (f a) (f b)))))))))))<br>    (syntax-case s ()<br>      ((_ (c) body ...)<br>       (syntax-case #&#39;c (else)<br>         ((else binds ...)<br>          #&#39;(let (binds ...) body ...))<br>

         ((t binds ...)<br>          #&#39;(if t (let (binds ...) body ...) (void)))))<br>      ((_ (c cs ...) body ...)<br>       (syntax-case #&#39;c ()<br>         ((t binds ...)<br>          #`(let #,(syntax-case #&#39;(c cs ...) ()<br>

                     (((_ (i _) ...) ...)<br>                      (map (λ (i) #`(#,i null))<br>                           (remove-duplicates-by<br>                            syntax-&gt;datum<br>                            (syntax-&gt;list #&#39;(i ... ...))))))<br>

              (if t<br>                  (let (binds ...) body ...)<br>                  (condlet (cs ...) body ...)))))))))</span><br><br>Any help is appreciated.<br>
<br>____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>