This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Macro expansion problem
On May 20, 2009, at 3:24 AM, Per Bothner wrote:
Somehow the define-input in the pattern fails to
match the define-input in the literals list,
so define-input is read as a pattern variable.
Just in case this is not clear: the definition of define-input as a
macro (which was not included in Per's quotation of Dan's email) is
interacting badly with the use of define-input as an entry in the
literals list.
For example, after applying the following changes (alpha-renaming the
define-input macro definition to define-input-alt) in a separate copy
x2.scm, I get different behavior. This suggests a straight-forward
work-around for Dan's problem, though of course that may not satisfy
his long-term goals.
% diff -u x.scm x2.scm
--- x.scm 2009-05-20 08:16:48.000000000 -0400
+++ x2.scm 2009-05-20 08:17:27.000000000 -0400
@@ -12,9 +12,9 @@
'lambda
`(()
- (define-syntax define-input
+ (define-syntax define-input-alt
(syntax-rules ()
- ((define-input var)
+ ((define-input-alt var)
(define var 1))
))
@@ -25,7 +25,7 @@
((test-out (test-content-type! expr ...))
(test-content-type! expr ...))
((test-out (define-input form))
- (mtrace1 (define-input form)))
+ (mtrace1 (define-input-alt form)))
((test-out expr) (display expr ))
))
(test-out ,@exprs))))
----
Here is the output from the runs on Kawa 1.9.1:
% java -jar kawa-1.9.1.jar
#|kawa:1|# (load "x.scm")
Trace1: (symbol->string (quote b))
#|kawa:2|# (load "x2.scm")
b
#|kawa:3|#
----
I tried the loading the files in a few other Scheme systems.
* The behavior of mzscheme (PLT Scheme v4.1.5) does not distinguish
x.scm and x2.scm.
* Larceny 0.963 errors loading either file (it is not portable R5RS to
have define-syntax in an internal definition context).
----
I spent some time playing around with different uses of let-syntax to
see if I could explore Larceny's behavior for cases like this, since
the scoping rules for the literals list do not seem obvious to me.
(Similar problems are often associated on the plt-scheme mailing list
with the refrain "the top-level is hopeless"; but in this case your
syntax definitions are within a lambda-expression, which means that it
really should not be attributed to a problem with the top-level REPL.)
It looks to me like Kawa's behavior with respect to the literals list
is not consistent with the behavior of Larceny nor PLT.
At the end of this email I have included the output I get with my test
file, illustrating how kawa's behavior differs from that of Larceny
(and PLT Scheme); the output is followed by the test file itself.
-Felix
% /usr/local/bin/larceny
Larceny v0.963 "Fluoridation" (Jul 29 2008 20:26:38, precise:Posix
Unix:unified)
/home/pnkfelix/.larceny: adding (lib/Experimental lib/Contrib) to
require path
larceny.heap, built on Tue Jul 29 20:28:40 EDT 2008
> (load "x3.scm")
((els1 in-a) (lit1 in-b) (els1 ((2 in-c))) (lit2 in-d) (els3 ((4 in-
e))) (els5 ((6 in-f))) (lit8 in-g))
> (exit)
% /Applications/PLT\ Scheme\ v4.1.5/bin/mzscheme
Welcome to MzScheme v4.1.5 [3m], Copyright (c) 2004-2009 PLT Scheme Inc.
> (load "x3.scm")
((els1 in-a) (lit1 in-b) (els1 ((2 in-c))) (lit2 in-d) (els3 ((4 in-
e))) (els5 ((6 in-f))) (lit8 in-g))
> (exit)
% java -jar kawa-1.9.1.jar
#|kawa:1|# (load "x3.scm")
((els1 in-a) (lit1 in-b) (lit1 in-c) (lit2 in-d) (lit3 in-e) (lit5 in-f)
(lit8 in-g))
#|kawa:2|# (exit)
%
;;; x3.scm -- explore behavior of scope in local macro's and literals
list
(define (f)
(let-syntax ((testm1 (syntax-rules (local-macro)
((testm1 (local-macro e)) `((lit1 ,e)))
((testm1 e) `((els1 ,e))))))
(append
(testm1 'in-a)
(testm1 (local-macro 'in-b))
(let-syntax ((local-macro (syntax-rules ()
((local-macro e) `((2 ,e))))))
(append
(testm1 (local-macro 'in-c))
(let-syntax ((testm2 (syntax-rules (local-macro)
((testm2 (local-macro e))
`((lit2 ,e)))
((testm2 e)
`((els2 ,e))))))
(testm2 (local-macro 'in-d)))
(let-syntax ((testm3 (syntax-rules (local-macro)
((testm3 (local-macro e))
`((lit3 ,e)))
((testm3 e)
`((els3 ,e)))))
(local-macro (syntax-rules ()
((local-macro e)
`((4 ,e))))))
(testm3 (local-macro 'in-e)))
(let-syntax ((testm5 (syntax-rules (local-macro)
((testm5 (local-macro e))
`((lit5 ,e)))
((testm4 e)
`((els5 ,e))))))
(let-syntax ((local-macro (syntax-rules ()
((local-macro e)
`((6 ,e))))))
(testm5 (local-macro 'in-f))))
(let-syntax ((local-macro (syntax-rules ()
((local-macro e)
`((7 ,e))))))
(let-syntax ((testm8 (syntax-rules (local-macro)
((testm8 (local-macro e))
`((lit8 ,e)))
((testm8 e)
`((els8 ,e))))))
(testm8 (local-macro 'in-g))))
)))))
(display (f))
(newline)