[gambit-list] Macros, separate files, and all that

Marc Feeley feeley at iro.umontreal.ca
Thu Jan 31 14:25:42 EST 2013


I don't have access to your code, but it looks like you have a phasing problem.  The macro definition needs to be available when code that uses the macro is compiled (because the macro's body needs to be executed to perform the code transformation).  What I usually do in such cases is to split the source code in two parts "streams#.scm" which contains the macro definitions and "streams.scm" which contains the rest of the code (function definitions).  Then the file "sieve.scm" should *include* the file "streams#.scm".  That way, the files "streams.scm" and "sieve.scm" can be compiled separately.  I'm sure you will notice the similarity with the C model (which separates ".h" and ".c" files).

Please check examples/distr-comp and specifically "dc.scm" and "dc#.scm" for an example.

Marc


On 2013-01-31, at 1:38 PM, Bradley Lucier <lucier at math.purdue.edu> wrote:

> Marc:
> 
> Assume that there's a file called "streams.scm" that has Phil Bewig's streams code in it, and that there's a file called "sieve.scm" that uses the definitions in streams.scm
> 
> Now, when I do
> 
> [Media-Mac-mini-3:~/Downloads] lucier% gsi -:s
> Gambit v4.6.6
> 
>> (load "streams.scm")
> "/Users/lucier/Downloads/streams.scm"
>> (load "sieve.scm")
> "/Users/lucier/Downloads/sieve.scm"
>> (stream->list 10 primes) 
> (2 3 5 7 11 13 17 19 23 29)
> 
> everything works fine.  But if I compile the streams code and do
> 
> [Media-Mac-mini-3:~/Downloads] lucier% gsi -:s
> Gambit v4.6.6
> 
>> (load "streams")
> "/Users/lucier/Downloads/streams.o3"
>> (load "sieve.scm")
> *** ERROR IN #<procedure #2>, "sieve.scm"@5.6 -- Unbound variable: define-stream
> 
> then, as you can see, a macro from streams.o3 is not available for use in expanding sieve.scm.
> 
> So, I guess I don't understand the "persistence" or whatever you would call it of R5RS macros, and how that interacts with Gambit's compilation model.
> 
> Can you help?
> 
> Brad
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list