Re: spec 3.1.2.1.2 and the lambda exception
From: Kaz Kylheku (kaz_at_ashi.footprints.net)
Date: 08/24/04
- Next message: nikodemus_at_random-state.net: "Common-lisp.net down due to attack"
- Previous message: Camm Maguire: "GCL 2.6.5 Solaris errata"
- In reply to: Ross Lippert: "spec 3.1.2.1.2 and the lambda exception"
- Next in thread: Pascal Bourguignon: "Re: spec 3.1.2.1.2 and the lambda exception"
- Reply: Pascal Bourguignon: "Re: spec 3.1.2.1.2 and the lambda exception"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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?
- Next message: nikodemus_at_random-state.net: "Common-lisp.net down due to attack"
- Previous message: Camm Maguire: "GCL 2.6.5 Solaris errata"
- In reply to: Ross Lippert: "spec 3.1.2.1.2 and the lambda exception"
- Next in thread: Pascal Bourguignon: "Re: spec 3.1.2.1.2 and the lambda exception"
- Reply: Pascal Bourguignon: "Re: spec 3.1.2.1.2 and the lambda exception"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|