[racket] Managing communication between two macro invocations at the top-level
I should say I renamed id to I in my test file because it conflicted with syntax/parse's required binding.
-Ian
----- Original Message -----
From: "J. Ian Johnson" <ianj at zimbra.ccs.neu.edu>
To: "Asumu Takikawa" <asumu at ccs.neu.edu>
Cc: "Racket Users" <users at racket-lang.org>, "Matthias Felleisen" <matthias at ccs.neu.edu>
Sent: Monday, July 21, 2014 10:06:26 AM GMT -05:00 US/Canada Eastern
Subject: Re: [racket] Managing communication between two macro invocations at the top-level
In a top-level begin, you can put a begin-for-syntax, so the following definition works for your example:
(define-syntax (def-and-use-of-x stx)
(syntax-parse stx
[(def-and-use-of-x val)
(with-syntax ([gen-id (generate-temporary)])
#'(begin (begin-for-syntax (set! I #'gen-id))
(define gen-id val) (displayln gen-id)))]))
----- Original Message -----
From: "Asumu Takikawa" <asumu at ccs.neu.edu>
To: "Matthias Felleisen" <matthias at ccs.neu.edu>
Cc: "Racket Users" <users at racket-lang.org>
Sent: Monday, July 21, 2014 9:50:24 AM GMT -05:00 US/Canada Eastern
Subject: Re: [racket] Managing communication between two macro invocations at the top-level
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
____________________
Racket Users list:
http://lists.racket-lang.org/users