thanks! this is all much clearer now :-)

On Sun, Jan 25, 2009 at 11:39 AM, Marc Feeley <feeley@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