why does this line doesn't work?

Discussion of Common Lisp

why does this line doesn't work?

Postby 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 ?
brooks
 
Posts: 3
Joined: Tue Jul 26, 2011 11:23 pm

Re: why does this line doesn't work?

Postby 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.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: why does this line doesn't work?

Postby 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))) '+ )
brooks
 
Posts: 3
Joined: Tue Jul 26, 2011 11:23 pm

Re: why does this line doesn't work?

Postby gugamilare » Wed Jul 27, 2011 9:39 am

If would be better if you do

Code: Select all
(lambda (f) (funcall f 1 2))  '+ )
gugamilare
 
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil

Re: why does this line doesn't work?

Postby 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)) '+)
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: why does this line doesn't work?

Postby brooks » Wed Jul 27, 2011 7:00 pm

Oh yes, It's really what my want. Thanks a lot.
brooks
 
Posts: 3
Joined: Tue Jul 26, 2011 11:23 pm


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron