hi
how to make this code work with gambit-c? (define (func x y) (+ x y)) (eval (cons func '(1 2)))
Thanks.
Afficher les réponses par date
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