Subject: Re: LISP
From: (Rob Warnock)
Date: Tue, 12 May 2009 19:33:51 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Kent Pitman <> wrote:
| (Rob Warnock) wrote:
| > That is, to me (LAMBDA ...something...) is an executable form [albeit
| > a special form] which returns a value, a new function which has closed
| > over its free variables with the current dynamic values of the lexically
| > visible bindings in the current environment. This doesn't seem like
| > "naming" to me so much as "creating", since the resulting closure you
| > get back is [potentially] *different* every time you execute the LAMBDA.
| > Contrast that with (FUNCTION FOO), which always gives you the *same*
| > [functional value of] FOO every time [modulo runtime redefinitions].
| >
| > Yes, a LAMBDA form with no free variables is also a "constant" name,
| > which is why I don't argue with Kent's view that "naming" is the more
| > important aspect. I suspect [but will wait for him to confirm or deny]
| > that most of the LAMBDAs he writes don't depend on captured free
| > variables. But for me, who even in CL uses lots of "functions which
| > generate functions" [i.e., non-trivial closures], the reverse is true.
| > That's why I, for one, am *very* glad that the LAMBDA *macro* exists
| > in CL, so that I can use it -- *without* the #' or FUNCTION prefix --
| > to make it very clear when I'm generating a value [a closure] and not
| > "just" naming something static & anonymous.  ;-}  ;-}
| But you are not, in point of fact, creating a function. #'(lambda (x) x)
| will not cons anything in most implementations.  It's permitted to cons,
| but not required to, and most implementations will return a constant
| object because no closure is required.

Of course not. But (LAMBDA (X) (+ X Y)) *will* cons, at least in those
cases where the closure value escapes the current lexical contour.

[If it doesn't escape, then, yes, most implementations will rewrite
the application to a LET binding.]

| [Perhaps you're saying you use #'(lambda ...) for lambdas of the first
| kind and (lambda ...) for lambdas of the second kind--I'm not sure.]

Bingo. If it doesn't capture any free variables, then it's a "constant"
(or equivalent to one), and #' can be used to "name" it without confusion.
But if it *does* capture free variables, then it's an executable form
producing a value and should look like such.

And since I originally came to CL from the Scheme world[1], I had gotten
into the habit of using LAMBDAs of the second kind, and still tend to
use them in CL more frequently than I see them in other people's CL code.


p.s. Where incremental currying by closing over this or that
is *very* common! Nesting LAMBDAs two or three deep is frequent,
and four is not unknown [though five or more is rare].

Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607