Re: spec 3.1.2.1.2 and the lambda exception

From: Kaz Kylheku (kaz_at_ashi.footprints.net)
Date: 08/24/04


Date: 23 Aug 2004 16:48:52 -0700

Ross Lippert <lippert@MATHSTATION031.MIT.EDU> wrote in message news:<mkj7jrpadi1.fsf@MATHSTATION031.MIT.EDU>...
> However, I can do
> ((lambda (y) (+ 1 y)) 1)
> without having to use funcall, though doing
> (funcall (lambda (y) (+ 1 y)) 1)
> works too.

I don't know whether this will help, but one way to look at this is
not that an exception is made for allowing a lambda expression to
serve in place of a function name in the first position of an
expression, but rather that a LAMBDA macro exists as a convenience so
that you don't have to use the FUNCTION operator or its #' shorthand
when you need an a funtion object elsewhere in an expression.

The reason you can write

  (funcall (lambda ...))

at all is that there exists a LAMBDA macro which rewrites (LAMBDA ...)
into (FUNCTION (LAMBDA ...)). In other words, it translates a lambda
expression into a call of the appropriate operator that actually
generates the closure from a lambda expression. Funcall needs a
closure or a symbol.

Without the macro, you would have to write:

  (funcall #'(lambda ...))

This is the special case. Other function names have to be treated
explicitly:

  (funcall #'y x) ;; NOT (funcall y x)

> The reason seems to come down to a place in the CL spec called
> 3.1.2.1.2 which says that the car of the s-exp to be interpreted must
> be a special form, a macro, a symbol or a lambda expression.
> http://www.lispworks.com/reference/HyperSpec/Body/03_abab.htm

Lambdas in the first position of a list are deeply traditional. Before
the LET operator was invented, that is how you wrote a block of code
with local variables. Superficially,

  (LET ((X A) (Y B)) ...)

is equivalent ot

  ((LAMBDA (X Y) ...) A B)

but it's more convenient because it juxtaposes the variables with the
expressions that provide their initial values.

> I guess that 3.1.2.1.2 allows lambdas and no other expressions
> because either:
> 1) there is some good reason to allow lambda expressions in the car.
> 2) there is some good reason to disallow arbitrary function-returning
> expressions in the car.

There is a good reason for 2, because then (FOO) is ambiguous. Do we
use the function binding of FOO to produce the function? Or do we
follow the value binding?



Relevant Pages

  • Re: spec 3.1.2.1.2 and the lambda exception
    ... >> without having to use funcall, ... > serve in place of a function name in the first position of an ... but rather that a LAMBDA macro exists as a convenience so ...
    (comp.lang.lisp)
  • Re: Casting problem
    ... For the same reason to use anonymous functions (at least one of the ... Actually I'm all-up for anonymous methods for delegates; ... abbreviated lambda syntax. ... delegates in one method call. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Corriolis force
    ... Mike Coslo wrote: ... and lambda is the wavelength. ... The reason that your experiment won't work is that ...
    (rec.radio.amateur.antenna)
  • Re: The 13.7 billion light-year length denotes a fifth spatial dimension.
    ... Now it is nice that you feel the need to repeatedly post Wikipedia links but ... not the huge lambda found in the Cosmic_Inflation theory. ... have to come up with a reason for having a "fifth" spatial dimension but you ...
    (sci.physics)
  • Re: whats wrong with "lambda x : print x/60,x%60"
    ... > Why would one need print in lambda? ... > is ugly work around though still 100% functional). ... I dashed that last part off quickly, so I don't have a good reason. ... Prev by Date: ...
    (comp.lang.python)

Loading