The problem with your first example is that there are some extra
scopes on `#'x` from the context that it's in. If you use
`(datum->syntax #f 'x)` (producing a syntax object with no scopes on
it) then your tests pass.

What `syntax-local-introduce` does is add precisely the scope that the
expander added to indicate the input to the macro that you're
defining. That allows you to pretend that things that were inputs were
not, or that things that were not inputs actually were. And since the
management of scopes is precisely what ensures hygiene,
`syntax-local-introduce` is unhygenic.

Sam

On Mon, May 2, 2016 at 9:53 AM, Matthew Butterick <m...@mbtype.com> wrote:
>
> On May 2, 2016, at 9:10 AM, Sam Tobin-Hochstadt <sa...@cs.indiana.edu> wrote:
>>
>> No, `syntax-local-introduce` is not hygenic. It's basically "pretend
>> that this identifier was in the input", which is fundamentally
>> unhygenic.
>
>
> Sorry to be dense, but I still don't see the "pretend that this identifier 
> was in the input" angle. Below, example 1 fails with an unbound-identifier 
> error, because the `syntax-local-introduce` identifier does not capture the 
> use-site reference. Whereas example 2 works, even though the `invoke-x` macro 
> ostensibly uses a hygienic reference.
>
> Having looked at the scope sets, I now understand WHY the behavior below 
> happens. But `syntax-local-introduce` clearly does something quite different 
> from, say, `(datum->syntax caller-stx datum)` (whose behavior I think of as 
> "pretend that this identifier was in the input").
>
>
> ;;;;;;;;;;;;;;;
>
> #lang racket
> (require rackunit)
>
> (module macros racket
>   (provide (all-defined-out))
>   (define-syntax (sli-x stx)
>     (syntax-case stx ()
>       [(_) (with-syntax ([x (syntax-local-introduce #'x)])
>              #'(define x 'syntax-local-introduce-x))]))
>
>   (define-syntax-rule (invoke-x) x))
>
> (require 'macros)
>
> ;; example 1
> (check-equal?
>  (let ()
>    (sli-x)
>    x) 'syntax-local-introduce-x)
>
> ;; example 2
> (check-equal?
>  (let ()
>    (sli-x)
>    (invoke-x)) 'syntax-local-introduce-x)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to