[plt-scheme] syntax-local-context?
jos koot skrev:
> The following confuses me:
>
> (define-syntax (show-local-context stx)
> (syntax-case stx ()
> ((show-local-context x)
> (let ((x (syntax x)))
> (printf "~s ~s.~n" (syntax-object->datum x) (syntax-local-context))
> x))))
>
> (let ((d (show-local-context (add1 2)))) d) ; --> 3
> ; displayed: (add1 2) top-level.
>
> I expected display: (add1 2) expression. Do I misunderstand the manual
> or (less probably) is this a bug?
When
(show-local-context (add1 2))
is expanded the transformer associated with
show-local-context is called.
The return value of the transformer is
a syntax object containing (add1 2).
The expander then expands (add1 2), and it
becomes (#%app add1 2).
Now the expanded result is evaluated, and the
result of evaluating (#%app add1 2) is 3.
To get what you expected, you need to let the
transformer return a syntax object representing
a quotation of the expressions. That is:
(define-syntax (show-local-context stx)
(syntax-case stx ()
((show-local-context x)
(let ((x (syntax x)))
(printf "~s ~s.~n" (syntax-object->datum x)
(syntax-local-context))
#''x))))
--
Jens Axel Søgaard