[racket] Need help with macro...

From: FS Racket (fsracket at gmail.com)
Date: Sun Feb 12 16:53:35 EST 2012

> In the example that doesn't work, the first mult is needed for another use
> of ==>. In the simpler examples, it is not. Notice that the orphaned mult
> occurs on the second step when another use is expanded, while in the
> simpler examples another use of ==> does not occur.  In the simple cases,
> mult is known to the expanded code; in the example that doesn't work, mult
> is not known to repeated use of the macro. Another clue is: if you run the
> test in the interactions window, it works because the definition of mult
> (in definitions) is automatically provided for interactions.
> I haven't even read your macro; the amazing and amusing macro stepper
> knows all and tells all.
Your comment caused me to think about why the repeated calls to ==> would
'mult' to become "unknown".  Eventually, I realized that the syntax->datum
call was probably doing too much; i.e. it was stripping away too much
information so when I built back up the new expression, the binding of
'mult' was lost.

At least, that's my guess.  I think the Racket documentation is fantastic
but I find a bit of experimentation is necessary to figure some things out
and that's what I've come up with.  (Perhaps an experience macrologist can

Anyhow, here's a version that works (er...at least it seems to work so

(define-syntax ==>
  (lambda (stx)
    (define (replace-in-first exp-list new-val)
      (let* ([new-exp
              (map (λ (x)
                     (if (eq? (syntax-e x) '_)
                   (syntax->list (car exp-list))) ]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120212/881aa25e/attachment.html>

Posted on the users mailing list.