This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

why does this line doesn't work?

6 posts · 1551 views

I'm using GNU Common Lisp(gcl), when I wrote:

( (lambda (f) (f 1 2)) '+ )

gcl complains:The Function F is undefined. why? It's invalid to pass a function to lambda macro ?

Re: why does this line doesn't work?

You probably should not be using GCL. I don't believe it is really maintained anymore, and it doesn't fully conform to the ANSI standard. SBCL is one of the more commonly used open source Common Lisp implementations.

Lambda is not a macro in this context, and calling functions in value space (such as those passed as arguments) doesn't work like this in Common Lisp. I suggest reading a book like Practical Common Lisp where this is explained in detail.

Re: why does this line doesn't work?

thanks.

I am reading Practical Common Lisp and now I understand the correct code should be:

(lambda (f) (apply f '(1 2))) '+ )

Re: why does this line doesn't work?

If would be better if you do
(lambda (f) (funcall f 1 2))  '+ )

Re: why does this line doesn't work?

Your first example was calling f incorrectly. The next two code samples aren't syntactically correct. I believe this is what you want (and very close to what you started with).
((lambda (f) (funcall f 1 2)) '+)

Re: why does this line doesn't work?

Oh yes, It's really what my want. Thanks a lot.