On 2012-04-19, at 3:04 PM, Kirill Zorin wrote:
Hi all,
The following program runs correctly in the interpreter, but fails when run with a generated executable.
(define-syntax foo (syntax-rules () ((_) "hi!\n"))) (display (eval '(foo)))
Running the generated executable fails with "*** ERROR -- Unbound variable: foo".
Am I doing something wrong?
Normally, when using define-macro, macros defined in a file are local to that file and they are not visible to eval. So the following will generate an error in the interpreter and compiler:
(define-macro (foo) "hi!\n") (display (eval '(foo)))
The reason your code works in the interpreter is that you are using the psyntax implementation of define-syntax which works by mutating the expansion-time global environment. Because the interpreter's expansion-time global environment is also the run-time global environment used by eval, it is possible to use the foo macro in the code evaluated.
To get your code working in the interpreter and compiler, you should do something like this:
(eval '(load "~~lib/syntax-case")) (eval '(define-syntax foo (syntax-rules () ((_) "hi!\n")))) (display (eval '(foo)))
Marc