Scheme -> Lisp. How can I pass a function as parameter to another function ?
Hi
I am trying to find how to do the following in Lisp:
( (lambda (f) ( f '(b c ))) (lambda (x) (cons 'a x)))
(answer ;Value 2: (a b c) )
This (directly from Graham's Roots of Lisp) works in Scheme.
According to Graham, in Lisp I should do:
( (lambda (f) ( f '(b c ))) '(lambda (x) (cons 'a x)))
But there is no way I can get this to work in Common Lisp (emacs lisp+cl, or CMU Common Lisp). Using 'quote' or 'function ' does not help at all.
emacs gives me
*** Eval error *** Symbol's function definition is void: f
CMU gives me
; In: (LAMBDA (F) (F '#)) '(LAMBDA (X) (CONS 'A X))
; ((LAMBDA # #) '(LAMBDA # #))
; Note: Variable F defined but never used.
; ;
; Warning: This function is undefined:
; F
Error in KERNEL:%COERCE-TO-FUNCTION: the function F is undefined.
[Condition of type UNDEFINED-FUNCTION]
Splitting the two by defining (defun fo (x) (cons 'a x)) first, does not help either.
I am clueless, what is the way to do such a simple thing ?
Cheers
|