At Tue, 3 May 2016 12:48:47 -0700, Matthew Butterick wrote:
> > Strangely, your Example #4 works the same as example #3, except in
> > DrRacket, where it errors.
>
> It's always nice to share puzzlement ;)
The problem is in `expand` and definition contexts. The problem doesn't
affect `compile`, which expands and converts to an AST at the same
time. Since DrRacket uses `expand`, the problem shows up there when it
doesn't show up when running plain `racket`.
More specifically, the problem is in converting definitions to
`let-values` as opposed to `letrec-values`. If you have
(define x^{s1,s2} 1)
(define x^{s1} 2)
x^{s1,s2}
then the expansion changes that to
(let-values ([(x^{s1,s2}) 1])
(let-values ([(x^{s1}) 2])
x^{s1,s2}))
The expander wants to convert to nested `let-values` bindings, because
there are no references to defined variables on the right-hand sides of
the definition.
Unfortunately, that expansion doesn't make sense: If the outer
`let-values` has been in the source program, it would have created an
extra scope on `x^{s1}` that does not appear in the binding
`x^{s1,s2}`. Re-expansion or compilation of the nonsensical expansion
runs into trouble:
(let-values ([(x^{s1,s2}) 1]) ; binding scope s3 added to body
(let-values ([(x^{s1,s3}) 2]) ; bining scope s4 added to body
x^{s1,s2,s3,s4}))
At this point, `x^{s1,s2,s3,s4}` is ambiguous.
The solution may be to change the expansion of definition contexts so
it produces something like
(let-values ([(x^{s3}) 1])
(let-values ([(x^{s3,s4}) 2])
(letrec-syntaxes ([(x^{s1}) (make-rename-transformer #'x^{s3})]
[(x^{s1,s2}) (make-rename-transformer #'x^{s3,s4})]
x^{s1,s2}))))
which uses nestable identifiers for the `let-values` bindings.
----------------------------------------
On the original question of what to do with `syntax-local-introduce`:
the main use case is when an identifier X is passed to macro invocation
A, and A wants to squirrel X away somewhere not covered by the
expander's remarking of A's result.
For example, if A attaches X as a syntax property, then it might use
`syntax-local-introduce` to get a variant of X to attach so that it's
consistent with the provided X.
So far, I don't know how to specify `syntax-local-introduce` other than
by its interaction with the expansion algorithm. The uses I can think
of offhand are places that want to imitate the expansion algorithm in
some way.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.