[gambit-list] (eval (cons func '(1 2))) don't work
Bradley Lucier
lucier at math.purdue.edu
Mon Aug 20 13:20:05 EDT 2007
On Aug 20, 2007, at 4:05 AM, naruto canada wrote:
> (define (func x y) (+ x y))
> (eval (cons func '(1 2)))
If you type
[descartes:~] lucier% gsc
Gambit Version 4.0 beta 23
> (define (func x y) (+ x y))
> (cons func '(1 2))
(#<procedure #2 func> 1 2)
>
you see that the car of the list you just built is not a symbol, it's
a function, so eval doesn't like it:
> (eval (cons func '(1 2)))
*** ERROR -- Ill-formed expression
#<procedure #2 func>
1>
So quote "func" to make it a symbol:
> (cons 'func '(1 2))
(func 1 2)
> (eval (cons 'func '(1 2)))
3
Actually, I'm kind of surprised it worked, I didn't think Gambit's
eval took the user's environment into account ...
Brad
More information about the Gambit-list
mailing list