[racket] let-syntax referencing inner binding

From: Jon Rafkind (rafkind at cs.utah.edu)
Date: Mon Jul 11 20:51:38 EDT 2011

After a few minutes thought I guess this would be 3d-syntax. References
to top-level identifiers have no state associated with them whereas
inner bindings amount to closures.

On 07/11/2011 06:40 PM, Jon Rafkind wrote:
> The code mostly speaks for itself but I'm wondering why the reference to
> `test2' is a compilation error.
>
> #lang racket
>
> (define-for-syntax (test)
>   (printf "hello from test\n")
>   #'1)
>
> (define-for-syntax (do-it stx)
>   (define (test2)
>     (printf "hello from test2\n")
>     #'2)
>
>   ;; ok, prints "hello from test"
>   #'(let-syntax ([bar (lambda (s)
>                         (test))])
>       (bar))
>
>   ;; doesn't compile, compile: identifier used out of context in: test2
>   #;
>   #'(let-syntax ([bar (lambda (s)
>                         (test2))])
>       (bar)))
>
> (define-syntax (foo stx)
>   (do-it stx))
>
> (foo)
>
> #|
> ;; this fails because a reference is made to a binding at phase 1 from
> phase 0 code
> ;; compile: identifier used out of context in: p
> (define-syntax (xx stx)
>   (define p 2)
>   #'p)
>
> (xx)
> |#
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users



Posted on the users mailing list.