Lisp HUG Maillist Archive

Lambda Forms?

Here's a real geek question...

At various times over the past several decades I have migrated back and forth, between using #'(lambda ....) or simply stating (lambda ...). After scouring the documentation this morning, and examining the macro-expansions of these two form under various conditions, it appears to me that they are completely equivalent *EXCEPT* in the following circumstance...

Let's say I define a macro that takes args and ultimately quotes some of them:

(defmacro quoter (arg)
`(quote ,arg))

Then if I did the following:

(quoter (lambda ....)) 

I would end up with a quoted cons form.

But if I did the following, 

(quoter #'(lambda ...))

then I'd end up with a quoted closure. 

It appears that in all other situations the compiler automatically produces closures from lambda forms.

Is this reading correct?

David McClain
Chief Technical Officer
Refined Audiometrics Laboratory
4391 N. Camino Ferreo
Tucson, AZ  85750

email: dbm@refined-audiometrics.com
phone: 1.520.390.3995
web: http://www.refined-audiometrics.com
Skype: dbmcclain


Re: Lambda Forms?

David McClain <dbm@refined-audiometrics.com> writes:

> Here's a real geek question...
>
> At various times over the past several decades I have migrated back
> and forth, between using #'(lambda ....) or simply stating  (lambda
> ...). After scouring the documentation this morning, and  examining
> the macro-expansions of these two form under various  conditions, it
> appears to me that they are completely equivalent  *EXCEPT* in the
> following circumstance...
>
> Let's say I define a macro that takes args and ultimately quotes some
> of them:
>
> 	(defmacro quoter (arg)
> 		`(quote ,arg))
>
> Then if I did the following:
>
> 	(quoter (lambda ....))
>
> I would end up with a quoted cons form.
>
> But if I did the following,
>
> 	(quoter #'(lambda ...))
>
> then I'd end up with a quoted closure.
>
> It appears that in all other situations the compiler automatically
> produces closures from lambda forms.
>
> Is this reading correct?

In both cases you'll end up with a quoted cons form. #' is a reader
macro expanding into (FUNCTION ...). The REPL may mislead you by
printing such forms as #'...


Updated at: 2020-12-10 08:45 UTC