I have a problem loading a file which defines syntax. It does not work in Gambit although it works in other Schemes.
This is file x.scm:
(define-syntax x (syntax-rules () ((_) (display "x\n")))) (load "y.scm") (x) (y)
And this is y.scm:
(define-syntax y (syntax-rules () ((_) (display "y\n"))))
When I run Gambit I get an error:
$ gsi -:s x.scm x *** ERROR IN "x.scm"@8.2 -- Unbound variable: y
But this works in Gauche, Bigloo and Chicken:
$ gosh x.scm x y
$ bigloo -s -i x.scm x y
$ csi -qb x.scm x y
Who is right?
Afficher les réponses par date
Try (include "y.scm").
Rationale: In Gambit, syntax definitions are not visible across compilation-unit boundaries; each .scm file is a single compilation unit. However the INCLUDE form copies the text of the included file verbatim into the current compilation unit -- just like C #include -- so, much like C, you will want to factor out your syntax definitions into a separate "header file" and INCLUDE them where needed. On Jan 16, 2012 1:35 PM, "Sascha Ziemann" ceving@gmail.com wrote:
I have a problem loading a file which defines syntax. It does not work in Gambit although it works in other Schemes.
This is file x.scm:
(define-syntax x (syntax-rules () ((_) (display "x\n")))) (load "y.scm") (x) (y)
And this is y.scm:
(define-syntax y (syntax-rules () ((_) (display "y\n"))))
When I run Gambit I get an error:
$ gsi -:s x.scm x *** ERROR IN "x.scm"@8.2 -- Unbound variable: y
But this works in Gauche, Bigloo and Chicken:
$ gosh x.scm x y
$ bigloo -s -i x.scm x y
$ csi -qb x.scm x y
Who is right? _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On 2012-01-16, at 1:34 PM, Sascha Ziemann wrote:
I have a problem loading a file which defines syntax. It does not work in Gambit although it works in other Schemes.
This is file x.scm:
(define-syntax x (syntax-rules () ((_) (display "x\n")))) (load "y.scm") (x) (y)
And this is y.scm:
(define-syntax y (syntax-rules () ((_) (display "y\n"))))
When I run Gambit I get an error:
$ gsi -:s x.scm x *** ERROR IN "x.scm"@8.2 -- Unbound variable: y
But this works in Gauche, Bigloo and Chicken:
$ gosh x.scm x y
$ bigloo -s -i x.scm x y
$ csi -qb x.scm x y
Who is right?
Gambit takes the point of view that syntax definitions are local to a file. This makes sense for a compiled language. After all "load" is a procedure which executes at *run* time. So in that context in the code:
(define-syntax x (syntax-rules () ((_) (display "x\n")))) (load "y.scm") (x) (y)
you wouldn't expect that the meaning of the macro call (y) depends on what was loaded by the (load "y.scm"). Otherwise it would be impossible to compile code efficiently. The compiler would have to defer to run time most of the decisions which are normally done at compile time.
If you want to reuse the macro definitions from another file, just "include" that file.
I'm curious... what happens in gauche, bigloo and chicken when file x.scm is compiled? What is the behaviour when you execute the compiled file? My guess is that the semantics of the compiler and interpreter are inconsistent on those Scheme implementations.
Marc
2012/1/16 Marc Feeley feeley@iro.umontreal.ca:
I'm curious... what happens in gauche, bigloo and chicken when file x.scm is compiled? What is the behaviour when you execute the compiled file? My guess is that the semantics of the compiler and interpreter are inconsistent on those Scheme implementations.
I wasn't aware of this but you are right. Chicken fails during execution:
$ csc x.scm $ ./x x
Error: unbound variable: y
And Bigloo fails during compilation:
$ bigloo x-bigloo.scm
File "x-bigloo.scm", line 10, character 106: #(y) #^ *** ERROR:toplevel-init Unbound variable -- y 1 error occured, ending ...
Gauche does not compile to binaries.