[racket] Managing communication between two macro invocations at the top-level

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Mon Jul 21 09:50:24 EDT 2014

On 2014-07-21 09:18:05 -0400, Matthias Felleisen wrote:
> I have used this on one occasion. Does it work for you?

I don't think it will work because in my situation at the top-level, the
definition `(define a 10)` comes in a separate `begin` block (IOW, in another
interaction) which breaks the connection.

Here's an example showing the error you'd get:

  -> (define-for-syntax id #f)
  -> (define-syntax (def-and-use-of-x stx)
       (syntax-parse stx
         [(def-and-use-of-x val)
          (with-syntax ([gen-id (generate-temporary)])
            (set! id #'gen-id)
            #'(begin (define gen-id val) gen-id))]))
  -> (define-syntax (produce-id stx) id)
  -> (def-and-use-of-x 3)
  3
  -> (produce-id)
  ; g1: unbound identifier;
  ;  also, no #%top syntax transformer is bound
  ;   in: g1
  ; [,bt for context]

Cheers,
Asumu

Posted on the users mailing list.