~/testing$ cat test.scm (define-macro (foo x) `(list ,x ,x)) ~/testing$ gsc Gambit v4.4.2
(include "test.scm") (foo 2)
(2 2)
*** EOF again to exit ~/testing$ gsc -:dar -e '(load "~~/lib/modules/build")' -
(include "test.scm") (foo 2)
*** ERROR IN (console)@2.2 -- Unbound variable: ~#foo 1>
(define-macro (foo x) `(list ,x ,x)) (foo 2)
(2 2)
*** EOF again to exit ~/testing$
okay ... so under gsc, my macro works under bsc, it does not yet if I manually type it into bsc, it works
what's going on here? :-)
Afficher les réponses par date
For those unaware, ~~/lib/modules/build is referring to the blackhole module system.
On Fri, May 15, 2009 at 8:05 AM, lowly coder lowlycoder@huoyanjinjing.comwrote:
~/testing$ cat test.scm (define-macro (foo x) `(list ,x ,x)) ~/testing$ gsc Gambit v4.4.2
(include "test.scm") (foo 2)
(2 2)
*** EOF again to exit ~/testing$ gsc -:dar -e '(load "~~/lib/modules/build")' -
(include "test.scm") (foo 2)
*** ERROR IN (console)@2.2 -- Unbound variable: ~#foo 1>
(define-macro (foo x) `(list ,x ,x)) (foo 2)
(2 2)
*** EOF again to exit ~/testing$
okay ... so under gsc, my macro works under bsc, it does not yet if I manually type it into bsc, it works
what's going on here? :-)
okay ... so under gsc, my macro works under bsc, it does not yet if I manually type it into bsc, it works
what's going on here? :-)
First of all, what you probably intend to do in bsc is (import test). In traditional Gambit development, you need to do include in order to be able to use the macros in that file, but that is not the case in BH. import does the obvious thing for macros and normal defines alike.
But if you really mean include, here's what, how and why:
I will first explain what's going on, then a way to work around it, then why it is that way.
This is an ugly face of the fact that BH more or less, but not completely, bypasses Gambit's macros. BH does not override (understand) the include form. What happens is that when you evaluate the include form, BH will not interpret it, but just send it to Gambit, and nothing within the included file will be processed by BH.
In this case, a Gambit macro named foo will be created. Later on, when you invoke foo, BH will rename the foo symbol to refer to the REPL namespace, ~#. What Gambit sees is (~#foo 2), but there is no thing with that name.
A work around for this is to implement an include macro, for instance:
(define-macro (include fn) `(begin ,@(with-input-from-file fn (lambda () (read-all)))))
and use that.
The reason include is not supported by BH is the same reason namespace is not supported. It is needed in traditional Gambit development, but is in my opinion a flawed model. BH's facilities replace include. If you want it for some hack or so, you can easily implement it, but I prefer the behavior when BH does not do anything about include or namespace forms. Normally, you shouldn't use them, but if you do, you at least know that BH does not mess with them.
/Per