why does this line doesn't work?
why does this line doesn't work?
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 ?
( (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.
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))) '+ )
I am reading Practical Common Lisp and now I understand the correct code should be:
(lambda (f) (apply f '(1 2))) '+ )
-
- Posts: 406
- Joined: Sat Mar 07, 2009 6:17 pm
- Location: Brazil
- Contact:
Re: why does this line doesn't work?
If would be better if you do
Code: Select all
(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).
Code: Select all
((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.