[plt-scheme] defmacro problem in Swindle?
On Jun 2, michael rice wrote:
> Don't know what's going on here. Scheme code (206p1
> w/Swindle) just below doesn't work. Similar Common
> Lisp code further down works fine. Any ideas?
>
> (define sum
> (lambda (nums)
> (if (null? nums)
> 0
> `(+ ,(car nums) ,(sum (cdr nums))))))
>
> (defmacro (mac1 nums)
> `(+ 4 ,(sum nums)))
>
> > (sum '(1 2 3))
> (+ 1 (+ 2 (+ 3 0)))
> > (mac1 (1 2 3))
> . reference to undefined identifier: sum
You're running into the phase separation problem: in MzScheme macros
work in their own level, so they cannot use any run-time values. Se
the MzScheme documentation.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!