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: Pascal Costanza
Subject: Re: Nested Lambda function gives error in common lisp, guile, emacs lisp but works in scheme. Why?
Date: Sun, 07 Oct 2007 13:02:10 +0200
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

gnuist006@hotmail.com wrote:
Please explain the below errors:

[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
The following restarts are available:
USE-VALUE      :R1      You may input a value to be used instead.
ABORT          :R2      ABORT


Similar errors in emacs lisp.

Common Lisp (and presumably Emacs Lisp) is a Lisp-2, which means that function positions are evaluated differently than value positions. In order to treat a first-class value as a function, you have to shift it via FUNCALL. In order to yield a function as a first-class value, you have look it up with FUNCTION.

Your code works in Common Lisp when you do this:

(funcall (funcall (lambda (a) (lambda (b) (list a b))) 1) 2)

This looks inconvenient, but there are good reasons why one might prefer a Lisp-2 over a Lisp-1 (like Scheme). See http://www.dreamsongs.com/Separation.html

If you google for Lisp-2 and Lisp-1, you will find more information. There have been a number of discussions about this in comp.lang.lisp.


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/


reply via email to

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