From: Jeff
Subject: Compiling a lambda expression
Date: 
Message-ID: <xhCld.30091$V41.2319@attbi_s52>
Is there any way to compile an unnamed lambda function? For example, I
have a list of lambda expressions that are created at runtime and
executed in order (inside a DOLIST). However, this is done for quite
some time and I'd like to speed it up a bit.

 (setf foo #'(lambda (x) (1+ x))) => FOO
 (compiled-function-p foo) => NIL

This is in LispWorks. I was hoping there was a simple way to force
these lambdas to compile when they were created. Since they are
unnamed, I can't use COMPILE. Hopefully I'm just missing the knowledge
of some other CL function ;)

Jeff M.

-- 
(surf-to "http://www.retrobyte.org/")

From: Barry Margolin
Subject: Re: Compiling a lambda expression
Date: 
Message-ID: <barmar-00E0D9.01404914112004@comcast.dca.giganews.com>
In article <····················@attbi_s52>, "Jeff" <·······@gmail.com> 
wrote:

> Is there any way to compile an unnamed lambda function? For example, I
> have a list of lambda expressions that are created at runtime and
> executed in order (inside a DOLIST). However, this is done for quite
> some time and I'd like to speed it up a bit.
> 
>  (setf foo #'(lambda (x) (1+ x))) => FOO
>  (compiled-function-p foo) => NIL

If you compile the file that contains the above lines, it should return 
T.

> 
> This is in LispWorks. I was hoping there was a simple way to force
> these lambdas to compile when they were created. Since they are
> unnamed, I can't use COMPILE. Hopefully I'm just missing the knowledge
> of some other CL function ;)

Why can't you use COMPILE?  Its optional argument is the interpreted 
function that should be compiled:

(setq foo (compile nil foo))

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Jeff
Subject: Re: Compiling a lambda expression
Date: 
Message-ID: <kiDld.404413$D%.258707@attbi_s51>
Barry Margolin wrote:

> Why can't you use COMPILE?  Its optional argument is the interpreted 
> function that should be compiled:
> 
> (setq foo (compile nil foo))

Sweet. I knew I was just missing something simple. Thanks :)

-- 
(surf-to "http://www.retrobyte.org/")
From: Kalle Olavi Niemitalo
Subject: Re: Compiling a lambda expression
Date: 
Message-ID: <87oei0hq1a.fsf@Astalo.kon.iki.fi>
"Jeff" <·······@gmail.com> writes:

> Is there any way to compile an unnamed lambda function?

  (setf foo (compile nil #'(lambda (x) (1+ x))))

  (setf foo (compile nil `(lambda (x) (,operator x))))

Or, if you put (setf foo #'(lambda (x) (1+ x))) in a file or
function and COMPILE-FILE or COMPILE that, then the lambda will
also get compiled.  (I dont know if there are exceptions to this.)