Section 4.5 of Abdulaziz Ghuloum's PhD thesis is the earliest description 
I've seen of an algorithm: 
https://www.proquest.com/openview/f6a12fd14db7fd3ea85cfebbf72e0bc5

It also does not provide much justification.

The second example you give becomes more natural if you've considered 
simpler cases of macros in definition contexts first:

1. Macro-generated references may refer to locally defined names

(let ([x 'outer])
  (define x 'inner)
  (define-syntax-rule (m)
    x)
  (m))

2. Macros may abstract over define

(let ([x 'outer])
  (define-syntax-rule (m a)
    (define a 'inner))
  (m x)
  x)

3. Definitions splice out of begin, in order to allow macros to generate 
multiple definitions

(let ([x 'outer] [y 'outer])
  (define-syntax-rule (define2 a b)
    (begin
      (define a 'inner)
      (define b 'inner))
  (m x y)
  (list x y))

>From there, your second example is a macro simultaneously abstracting over 
a definition and referring to a locally defined name.
On Wednesday, July 28, 2021 at 1:31:25 AM UTC-6 lexi....@gmail.com wrote:

> Hi all,
>
> I recently posted two tricky hygiene puzzles on Twitter 
> <https://twitter.com/lexi_lambda/status/1420221128245714951>, reproduced 
> below for completeness:
>
>     (let ([x 'outer])
>       (define-syntax-rule (m a)
>         (let ([a 'inner]) x))
>       (m x))
>
>     (let ([x 'outer])
>       (define-syntax-rule (m a)
>         (begin
>           (define a 'inner)
>           x))
>       (m x))
>
> The puzzle is to guess what these expressions evaluate to. I have 
> discovered that people find the “correct” answer *remarkably* 
> unintuitive—at the time of this writing, it is the single least popular 
> choice in the poll!
>
> Despite this confusion, the Scheme implementations I’ve tried are 
> unwaveringly consistent in their interpretation of these expressions: 
> Racket, Chez, and Guile all agree on what the answers should be. This has 
> led me to wonder where the original justification for these answers comes 
> from, but I have been struggling to hunt down a source.
>
> Matthew’s 2016 paper, “Bindings as Sets of Scopes”, discusses examples 
> like these ones in gory detail, but it gives no justification for *why* 
> these results are the right ones, it simply takes their meaning for 
> granted. Earlier papers on macro technology I have found do not discuss 
> internal definitions, and no Scheme standard specifies the macro system, 
> not even R6RS. Obviously, something at some point must have set the 
> precedent for the handling of such macros, but I cannot figure out what it 
> is.
>
> So, my question: when was hygiene for internal definitions first worked 
> out, and did it make it into any papers, specifications, or documentation? 
> Hopefully someone (probably Matthew) can provide some insight.
>
> Thanks,
> Alexis
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/ef3475e3-1b06-44f0-86e4-087dc57034fen%40googlegroups.com.

Reply via email to