(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? [I would prefer that code in "gsi test.scm" has the same effect as if I type it into the interpreter] thanks in advance! -- -- symbolic expression
Afficher les réponses par date
Hi, These links should help: https://webmail.iro.umontreal.ca/pipermail/gambit-list/2006-May/000690.html https://webmail.iro.umontreal.ca/pipermail/gambit-list/2006-May/000692.html Bill On Sat, Jan 24, 2009 at 2:42 PM, symbolic expression < symbolic.expression@gmail.com> 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?
[I would prefer that code in "gsi test.scm" has the same effect as if I type it into the interpreter]
thanks in advance!
-- -- symbolic expression
_______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Essentially, you're calling `foo' during the macro expansion phase. Are you sure you didn't what the macro to *expand* to (foo x) instead? This would work: (define (foo x) (+ x 1)) (define-macro (bar x) `(foo ,x)) (bar 10) Otherwise, if you really are asking about the difference between expansion and runtime phases, see the two links Bill Six sent. - James On Jan 24, 2009, 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?
[I would prefer that code in "gsi test.scm" has the same effect as if I type it into the interpreter]
thanks in advance!
-- -- symbolic expression _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
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
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
participants (4)
-
Bill Six -
James Long -
Marc Feeley -
symbolic expression