In the scope sets document
(https://www.cs.utah.edu/~mflatt/scope-sets-5/pattern-macros.html#%28part._intdef%29)
it is claimed that the following is ambiguous:
(define-syntax-rule (def-m m given-x)
(begin
(define x 1)
(define-syntax-rule (m)
(begin
(define given-x 2)
x))))
(def-m m x)
(m)
Rather confusingly, it is only ambiguous when `def-m' is used in the same
definition context as where `def-m' is defined; the following is accepted with
the same interpretation as the old expander:
(let ()
(def-m m x)
(m))
But the following provokes an ambiguous binding error:
;; tested with 6.2.900.17--2015-09-29(3154908/a)
(def-m m x)
(let ()
(m))
I can't follow why this should be the case given the reasoning for why the
first example is ambiguous: "Absent the (define x 1) definition generated by
def-m, the final x reference should refer to the definition generated from
(define given-x 2)"; however, in the second permutation with the `let'
surrounding just the use of `m', this would never be the case in the old
expander, because that definition is not part of the same definition context.
After playing with various permutations of this, I encountered a behavior that
seems like a clear violation of referential transparency:
(define x 'outer)
(define-syntax-rule (def-m m given-x)
(define-syntax-rule (m)
(begin
(define given-x 'inner)
x)))
(def-m m x)
(let ()
(m))
Under the old expander, this yields 'outer; under the new expander, it yields
'inner. Under both expanders, the following yields 'outer:
(let ()
(def-m m x)
(let ()
(m)))
The definition introduced by (define given-x 'inner) should never capture the
use of `x' in `m', at least according to my mental model: either a given use of
`m' should provoke a duplicate binding error, or it should refer to the outer
`x'. I'm unable to find any convincing rationalization for why it would behave
otherwise. What am I missing?
--
Brian Mastenbrook
[email protected]
http://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/5F747682-8C7D-4654-802E-995E7BD7B1E0%40mastenbrook.net.
For more options, visit https://groups.google.com/d/optout.