[racket] datum<->syntax with same context, yet "unbound identifier"

From: Greg Hendershott (greghendershott at gmail.com)
Date: Wed Nov 21 11:35:28 EST 2012

Hi, Tobias.

> (define-syntax (lam stx)
>   (syntax-case stx ()
>     [(_ args body ...)
>      (with-syntax ([conv-args (for/list ([a (syntax->list #'args)])
>                                 (define a-datum (syntax->datum a))
>                                 ;; do whatever you want with a-datum
>                                 (datum->syntax a a-datum))])
>      #`(lambda conv-args
>          body ...))]))

Thank you! That makes sense. I was able to use this successfully in
the one spot where I couldn't avoid a trip through syntax->datum and
datum->syntax.

In the remaining places I was able to get things done with patterns --
and a small army of ellipses :) -- instead of using append* and more
datum<->syntax.

(In case anyone is interested, a less-distilled example is here:
https://gist.github.com/4122971/3e40c23c9390b9c5e3e91cd8293c25238e0cfaa3 )

> Other macros only have to cooperate in the 'normal' way, i.e. they have to
> make sure
> that the arguments they pass in have the right context.

Perfect. Many thanks!


P.S. I already appreciated that patterns/templates are usually more
convenient. However I seem to be learning that I should try to stick
with patterns/templates even when Racket normal code would be more
convenient -- because otherwise I'm likely to botch up the lexical
context. I'm curious what folks thinks: Is that a reasonable
take-away, good advice to give myself?

Posted on the users mailing list.