On 09/29/2015 09:23 PM, Matthew Flatt wrote:
When you step back, it sure looks non-hygienic, because

  (define-syntax-rule (def-and-use-m given-x)
    (begin
      (define-syntax-rule (m)
         (begin
           (define given-x 'inner)
           x))
      (m)))

looks like a reference to a `x` that should never be captured by any
`given-x`. The catch is that it's a free `x` with respect to the
context of `def-and-use-m`. In a context that allows both a definition
and a use of `def-and-use-m`, it can turn out that `given-x` is exactly
the identifier that the free `x` should refer to.

I'm afraid I'm still not following. To avoid confusing myself with multiple issues, I'll start with a version of `m' that does not involve splicing:

(define x 'outer)

(define-syntax-rule (def-and-use-m given-x)
  (begin
    (define-syntax-rule (m)
      (let ()
        (define given-x 'inner)
        x))
    (m)))

(def-and-use-m x)

As before, the old expander returns `outer' and the new expander returns `inner'.

The reason that this seems to violate hygiene to me is that if I change the definition of `m' to an ordinary procedure definition, I get 'outer from both expanders. It seems to me to be the very essence of hygiene that lexical capture works in macros the same way that it works in ordinary definitions, and I'm surprised that such minor transformations of the program are affecting the result in ways that don't seem to match my mental model for how things "should" work.

However, I admit that I have internalized the old rules in order to be able to reason about macro-generating macros, and am no longer able to understand the confusion I once had about these things in the marks-and-wraps model. Perhaps I just need to get used to the new model.

--
Brian Mastenbrook
[email protected]
https://brian.mastenbrook.net/

--
You received this message because you are subscribed to the Google Groups "Racket 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-dev/560B51C5.1070603%40mastenbrook.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to