<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 05/21/2012 06:02 AM, Matthew Flatt wrote:
<blockquote
cite="mid:20120521120238.A7216650094@mail-svr1.cs.utah.edu"
type="cite">
<pre wrap="">At Sun, 20 May 2012 22:42:30 -0600, Jon Rafkind wrote:
</pre>
<blockquote type="cite">
<pre wrap="">The issue is why do I have to use a name other than 'name' for the
pattern variable on the line where it says 'HERE'. If I use the
'name' pattern variable then the syntax-parse form generated by
'make-transformer' will use the wrong lexical context for the literal
set. I don't see how the lexical context of the outer 'name' differs
from the inner 'new-name', other than the 'new-name' has an extra
mark on it.
</pre>
</blockquote>
<pre wrap="">
When you use `name' instead of `new-name', then `name' gets replaced by
`x' from the use of `define-new-syntax', and `x' (unlike `name') has a
different lexical context than `new-name'.
</pre>
</blockquote>
<br>
I thought that too but while debugging it didn't seem to be the
case. If I put a printf in the 'make-transformer' macro to "see"
what name is being passed in then using 'name' or 'new-name' as the
pattern variable results in the same thing being printed.<br>
<br>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; white-space: pre-wrap; "> (begin-for-syntax
(define-syntax (make-transformer stx)
(syntax-parse stx
[(_ name pattern template)
(printf "Name is ~a\n" #'name)
#'#'(lambda (stx)
(syntax-parse stx
#:literal-sets ([literals #:at name])
[pattern template]))])))
</pre>
<br>
Then calling 'make-transformer' 3 different ways:<br>
<br>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; white-space: pre-wrap; ">(lambda (stx)
(syntax-parse stx
[(_ new-name)
(with-syntax ([output (make-transformer name pattern template)])
#'(define-syntax new-name output))]
</pre>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
"Name is #<syntax:x.rkt:56:19 x>", where line 56 is the
use-site of 'define-new-syntax'<br>
<br>
<pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; white-space: pre-wrap; ">(lambda (stx)
(syntax-parse stx
[(_ name)
(with-syntax ([output (make-transformer name pattern template)])
#'(define-syntax name output))]
</pre>
"Name is #<syntax:x.rkt:56:19 x>"<br>
<br>
<pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; white-space: pre-wrap; ">(lambda (stx)
(syntax-parse stx
[(_ new-name)
(with-syntax ([output (make-transformer new-name pattern template)]) ;; line 39
#'(define-syntax new-name output))]
</pre>
"Name is #<syntax:x.rkt:39:61 new-name>"<br>
<br>
It seems like the 2nd and 3rd cases should be similar in that the
2nd case should report #<syntax:x.rkt:39:61: x> as the source
instead of the original x from the use-site. So given that there is
a difference between the 1st and 2nd cases how can I "see" this?
printf doesn't seem to be the right tool.<br>
<br>
<br>
</body>
</html>