From: Fernando D. Mato Mira
Subject: To FUNCTION or to FLET?
Date: 
Message-ID: <38DB764A.98B58B61@iname.com>
In the different CL implementations, what is more efficient?

(funcall #'(lambda <arglist> <forms>) <args>)

or

(flet ((fun <arglist> <forms>))
   (declare (dynamic-extent #'fun))
   (fun <args>))

?

Also, which ones will generate overhead when the above
function definitions happen inside a loop, when they could be bound
surrounding it?

Thanks in advance,

--
Fernando D. Mato Mira
Real-Time SW Eng & Networking
Advanced Systems Engineering Division
CSEM
Jaquet-Droz 1                   email: matomira AT acm DOT org
CH-2007 Neuchatel                 tel:       +41 (32) 720-5157
Switzerland                       FAX:       +41 (32) 720-5720

www.csem.ch      www.vrai.com     ligwww.epfl.ch/matomira.html

From: Barry Margolin
Subject: Re: To FUNCTION or to FLET?
Date: 
Message-ID: <I2MC4.66$b22.1484@burlma1-snr2>
In article <·················@iname.com>,
Fernando D. Mato Mira <········@iname.com> wrote:
>In the different CL implementations, what is more efficient?
>
>(funcall #'(lambda <arglist> <forms>) <args>)
>
>or
>
>(flet ((fun <arglist> <forms>))
>   (declare (dynamic-extent #'fun))
>   (fun <args>))
>
>?
>
>Also, which ones will generate overhead when the above
>function definitions happen inside a loop, when they could be bound
>surrounding it?

I would expect most implementations to optimize the two forms to the same
code.  In fact, you shouldn't even need the DYNAMIC-EXTENT declaration,
since the compiler can see that #'FUN is never passed around as data, so it
can't be referenced outside the lexical and dynamic extent of the FLET.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Fernando D. Mato Mira
Subject: Re: To FUNCTION or to FLET?
Date: 
Message-ID: <38DBAEDA.2472A409@iname.com>
Barry Margolin wrote:

> code.  In fact, you shouldn't even need the DYNAMIC-EXTENT declaration,
> since the compiler can see that #'FUN is never passed around as data, so it
> can't be referenced outside the lexical and dynamic extent of the FLET.

I'm just paranoid ;)

--
Fernando D. Mato Mira
Real-Time SW Eng & Networking
Advanced Systems Engineering Division
CSEM
Jaquet-Droz 1                   email: matomira AT acm DOT org
CH-2007 Neuchatel                 tel:       +41 (32) 720-5157
Switzerland                       FAX:       +41 (32) 720-5720

www.csem.ch      www.vrai.com     ligwww.epfl.ch/matomira.html
From: Fernando D. Mato Mira
Subject: Re: To FUNCTION or to FLET?
Date: 
Message-ID: <38DB8345.7785D1FD@iname.com>
"Fernando D. Mato Mira" wrote:

> In the different CL implementations, what is more efficient?
>
> (funcall #'(lambda <arglist> <forms>) <args>)
>
> or
>
> (flet ((fun <arglist> <forms>))
>    (declare (dynamic-extent #'fun))
>    (fun <args>))
>
> ?

I guess the answer should be this:

((lambda <arglist> <forms>) <args>)


Except that the loop question still stands.

--
Fernando D. Mato Mira
Real-Time SW Eng & Networking
Advanced Systems Engineering Division
CSEM
Jaquet-Droz 1                   email: matomira AT acm DOT org
CH-2007 Neuchatel                 tel:       +41 (32) 720-5157
Switzerland                       FAX:       +41 (32) 720-5720

www.csem.ch      www.vrai.com     ligwww.epfl.ch/matomira.html