help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Nested Lambda function gives error in common lisp, guile, emacs lisp


From: Matthias Benkard
Subject: Re: Nested Lambda function gives error in common lisp, guile, emacs lisp but works in scheme. Why?
Date: Sun, 07 Oct 2007 17:09:19 -0700
User-agent: G2/1.0

> [1]> (((lambda (a) (lambda (b) (list a b))) 1) 2)
>
> *** - EVAL: ((LAMBDA (A) (LAMBDA (B) (LIST A B))) 1) is not a function
> name; try using a symbol
>       instead

As the others have already told you, you can't just put any arbitrary
expression in the CAR of a form to be evaluated.  Now, it's not quite
true that you can only use symbols in the CAR of evaluated forms,
either, because you can also put a lambda expression there.  Note that
by this I do not mean just any expression that evaluates to a function
object, but really simply a lambda expression: a list whose CAR is the
symbol LAMBDA (and which can be evaluated to a function object).  So
the following is valid and will yield 10:

((lambda (x) x) 10)

But the following is invalid (assuming you haven't defined a function
called FOO elsewhere):

(let ((foo (lambda (x) x)))
  (foo 10))

Note also that when in an evaluated position, (function (lambda ...))
and (lambda ...) are equivalent, but you can't use the former as the
CAR of a form to be evaluated, because it isn't a lambda expression.

I just wanted to mention this, because you may have already stumbled
upon it when experimenting, and the fact that (((lambda () (lambda
())))) is invalid while ((lambda ())) isn't may be confusing you
needlessly.  The point is that you should ignore the fact that
((lambda ())) works and pretend that it doesn't until you understand
why it's a special case.

~ Matthias



reply via email to

[Prev in Thread] Current Thread [Next in Thread]