[racket] reconstructing syntax objects

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Thu Nov 17 15:20:09 EST 2011

On 11/17/2011 12:28 PM, Jon Rafkind wrote:
> I have some code that deconstructs and reconstructs a syntax object. I'm
> pretty sure this code is at fault for not adding the proper lexical
> context back on so I get an error about 'no #%app bound'.
>
> (syntax-parse form
>   [(form ...)
>    (with-syntax ([(form* ...) (map honu->racket (syntax->list #'(form ...)))])
>      (datum->syntax forms
>                     #'(form* ...)
>                     forms
>                     forms))]
>
> I had hoped that datum->syntax would add the original lexical context
> back on, is it not doing what I hoped?

No, the datum->syntax there is a no-op, because #'(form* ...) is already 
a syntax object, and datum->syntax stops when it hits something that's 
already a syntax object.

You should do something like this instead:

   (datum->syntax forms
                  (map honu->racket (syntax->list #'(form ...)))
                  forms
                  forms)

Ryan


Posted on the users mailing list.