[gambit-list] define-syntax and loading files

Marc Feeley feeley at iro.umontreal.ca
Fri Jun 12 12:39:24 EDT 2009


Remember that "load" is a procedure that is called at run time, i.e.  
**when your program is executing**.

Macros are expanded at expansion time, which is something that happens  
before run time.

The bottom line is that you should not "load" files with macros to  
access those macros.  You have to "include" those files.

If you know the C world, the following analogy may help you understand:

    (include "foo")  ==>  #include "foo"
    (load "foo")     ==>  dlopen("foo",...)

Marc

P.S. in addition your call to the foo macro should be (foo xyzzy) .


On 12-Jun-09, at 10:47 AM, Taylor Venable wrote:

> I'm having some trouble understanding the behavioural differences in
> this code:
>
> BEGIN FILE test-alpha.scm --------------------------------------------
>
>    (define-syntax foo
>      (syntax-rules (xyzzy)
>        ((_ xyzzy) "nothing happens")))
>
> BEGIN FILE test-beta.scm ---------------------------------------------
>
>    (load "test-alpha.scm")
>
>    (define bar
>      (lambda ()
>        (foo hello)))
>
> ======================================================================
>
> If I load test-beta.scm twice, I get an error on the second load but
> not on the first one:
>
>> (load "test-beta.scm")
> "/home/taylor/cvs_public/Programs/Libraries/Scheme/test-beta.scm"
>> (load "test-beta.scm")
> *** ERROR IN %%chi-macro437, "/opt/gambit/lib/syntax- 
> case.scm"@9135.1 -- invalid syntax (foo hello)
>
> But if I do what seems like it should be the equivalent of loading
> test-alpha.scm, then loading test-beta.scm I get an error on the first
> load of test-beta:
>
>> (load "test-alpha.scm")
> "/home/taylor/cvs_public/Programs/Libraries/Scheme/test-alpha.scm"
>> (load "test-beta.scm")
> *** ERROR IN %%chi-macro437, "/opt/gambit/lib/syntax- 
> case.scm"@9135.1 -- invalid syntax (foo hello)
>
> It seems to me that loading test-beta by itself should be the same as
> loading test-alpha then test-beta, but it's not quite.  Why is this?
>
> For what it's worth, my Gambit version string is:
> v4.4.4 20090611032636 amd64-unknown-openbsd4.5
> "./configure --prefix=/opt/gambit --enable-single-host"
>
> Thanks,
>
> -- 
> Taylor Christopher Venable
> http://real.metasyntax.net:2357/
> _______________________________________________
> 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