[gambit-list] macro/function interaction

symbolic expression symbolic.expression at gmail.com
Sun Jan 25 17:10:35 EST 2009


thanks! this is all much clearer now :-)

On Sun, Jan 25, 2009 at 11:39 AM, Marc Feeley <feeley at iro.umontreal.ca>wrote:

>
> On 24-Jan-09, at 9:42 PM, symbolic expression wrote:
>
>  (define (foo x) (+ x 1))
>> (define-macro (bar x) (foo x))
>> (bar 10)
>>
>> this baffles me, if I open up gsi and paste this into the interpreter, I
>> get 11
>> however, if I stuff this in test.scm and run "gsi test.scm" I get:
>>
>> *** ERROR IN #<procedure #2>, "test.scm"@2.24 -- Unbound variable: foo
>>
>> what's going on? how do I fix this?
>>
>
> You are confusing the expansion time world and the run time world.  Check
> out the links Bill Six sent.
>
>
>>
>> [I would prefer that code in "gsi test.scm" has the same effect as if I
>> type it into the interpreter]
>>
>
> If that is really what you want you can replace
>
> % gsi test.scm
>
> by
>
> % gsi -e '(for-each eval (read-all (open-input-file "test.scm")))'
>
> or do that in a source file.
>
> Finally, you can always define foo locally to bar:
>
> (define-macro (bar x)
>  (define (foo x) (+ x 1))
>  (foo x))
>
> (bar 10)
>
> or put foo's definition in a file (say foo.scm) and then:
>
> (define-macro (bar x)
>  (include "foo.scm")
>  (foo x))
>
> (bar 10)
>
> Marc
>
>


-- 
-- symbolic expression
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20090125/a824fdd8/attachment.htm>


More information about the Gambit-list mailing list