[gambit-list] a black hole ate up my macros

Per Eckerdal per.eckerdal at gmail.com
Fri May 15 18:32:09 EDT 2009


> 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




More information about the Gambit-list mailing list