why does this line doesn't work?

Discussion of Common Lisp
Post Reply
brooks
Posts: 3
Joined: Tue Jul 26, 2011 11:23 pm

why does this line doesn't work?

Post by brooks » Wed Jul 27, 2011 1:12 am

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 ?

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: why does this line doesn't work?

Post by ramarren » Wed Jul 27, 2011 3:06 am

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.

brooks
Posts: 3
Joined: Tue Jul 26, 2011 11:23 pm

Re: why does this line doesn't work?

Post by brooks » Wed Jul 27, 2011 6:53 am

thanks.

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

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

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: why does this line doesn't work?

Post by gugamilare » Wed Jul 27, 2011 9:39 am

If would be better if you do

Code: Select all

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

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: why does this line doesn't work?

Post by nuntius » Wed Jul 27, 2011 9:56 am

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)) '+)

brooks
Posts: 3
Joined: Tue Jul 26, 2011 11:23 pm

Re: why does this line doesn't work?

Post by brooks » Wed Jul 27, 2011 7:00 pm

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

Post Reply