From: jronald
Subject: Basic question
Date: 
Message-ID: <eegsj8$l72$1@news.yaako.com>
Is "lambda" a key word in lisp?
The form with it I usually see is as below
(lambda (p0 p1 ...) e)

I can't understand it as in the following example, where the form is:
(lambda (...) (...) (...))
I don't know "function" in the example either.


sample code:

(add-hook 'asm-mode-hook
      (function
       (lambda ()
            (make-local-variable 'compile-command)
     (setq compile-command
                   (concat "make -k -e EXECUTABLE="
                   (file-name-sans-extension
                         (file-name-nondirectory buffer-file-name)))
               )))) 

From: dpapathanasiou
Subject: Re: Basic question
Date: 
Message-ID: <1158418855.474972.125980@i3g2000cwc.googlegroups.com>
"lambda" is neither a keyword nor a function name.

Instead, it's just a symbol to denote an anonymous function.

According to "ANSI Common Lisp" by Paul Graham, lambda as a symbol is a
hold-over from earlier dialects when the only way to tell a function
apart from an ordinary list was to start it with "lambda".

Also, just to confuse you completely, there's also a macro definition
for LAMBDA, which is different from lambda the symbol.

The CL hyperspec has more on those two definitions:
http://www.lispworks.com/documentation/HyperSpec/Body/a_lambda.htm

jronald wrote:
> Is "lambda" a key word in lisp?
> The form with it I usually see is as below
> (lambda (p0 p1 ...) e)
>
> I can't understand it as in the following example, where the form is:
> (lambda (...) (...) (...))
> I don't know "function" in the example either.
>
>
> sample code:
>
> (add-hook 'asm-mode-hook
>       (function
>        (lambda ()
>             (make-local-variable 'compile-command)
>      (setq compile-command
>                    (concat "make -k -e EXECUTABLE="
>                    (file-name-sans-extension
>                          (file-name-nondirectory buffer-file-name)))
>                ))))
From: Pascal Bourguignon
Subject: Re: Basic question
Date: 
Message-ID: <87irjo2b46.fsf@thalassa.informatimago.com>
"jronald" <·········@163.com> writes:

> Is "lambda" a key word in lisp?

Lisp keywords are symbols interned in the package named "KEYWORD".

They can be written as qualified symbols omiting the package name, and
they have the special property of being automatically defined as
constants having themselves as value.

   KEYWORD::EXAMPLE  and   :OTHER-EXAMPLE are lisp keywords.

Their values are themselves:

[6]> KEYWORD::EXAMPLE
:EXAMPLE
[7]> :OTHER-EXAMPLE
:OTHER-EXAMPLE



LAMBDA is not a keyword, unless the current package is the package
named "KEYWORD":


[8]> (in-package "KEYWORD")
#<PACKAGE KEYWORD>
KEYWORD[9]> 'lambda
:LAMBDA
KEYWORD[10]> (common-lisp:keywordp 'lambda)
COMMON-LISP:T
KEYWORD[11]> (common-lisp:in-package "CL-USER")
#<PACKAGE COMMON-LISP-USER>
[12]> 'lambda
LAMBDA
[13]> (keywordp 'lambda)
NIL
[14]> (eq 'common-lisp:lambda 'lambda)
T
[15]> (eq 'keyword:lambda ':lambda)
T
[16]> (eq 'lambda ':lambda)
NIL
[17]> 


Unqualified symbols are ambiguous, since they could be anything,
depending on the current package.


> The form with it I usually see is as below
> (lambda (p0 p1 ...) e)
>
> I can't understand it as in the following example, where the form is:
> (lambda (...) (...) (...))
> I don't know "function" in the example either.

If we're considering the symbol COMMON-LISP:LAMBDA, then it's
specified to be defined as a macro expanding a form like:

   (COMMON-LISP:LAMBDA (args...) expressions...)   ; this is a lambda expression

to:

   (COMMON-LISP:FUNCTION (COMMON-LISP:LAMBDA (args...) expressions...))

That's all.


COMMON-LISP:FUNCTION is defined to be a special form, resulting in a
function.  It usually takes a function name (a symbol) and returns the
function defined by that name.  But when it contains a lambda
expression, then it returns an anonymous function defined by this
lambda expression.




Now, the body of a function behaves as if it was inside a PROGN.

    (lambda (args...) e1 e2 ... en)

is equivalent to:

    (lambda (args...) (progn e1 e2 ... en))

(assuming the current package has imported the symbols CL:LAMBDA and CL:PROGN).



> sample code:
>
> (add-hook 'asm-mode-hook
>       (function
>        (lambda ()
>             (make-local-variable 'compile-command)
>             (setq compile-command
>                    (concat "make -k -e EXECUTABLE="
>                    (file-name-sans-extension
>                          (file-name-nondirectory buffer-file-name)))
>                )))) 

In emacs lisp, there are no packages.  The reader only uses a single
obarray for all the symbols it reads, and "keywords" are just symbols
whose names start with a ':' character.

For emacss, use C-h f to get the documentation of the operators:

C-h f lambda RET
C-h f progn RET
etc...

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.
From: Alex Mizrahi
Subject: Re: Basic question
Date: 
Message-ID: <450c0cde$0$75029$14726298@news.sunsite.dk>
(message (Hello 'jronald)
(you :wrote  :on '(Sat, 16 Sep 2006 21:01:29 +0800))
(

Pascal Bourguignon's answer is a bit too long, so here is shorter.

 j> Is "lambda" a key word in lisp?
 j> The form with it I usually see is as below
 j> (lambda (p0 p1 ...) e)

 j> I can't understand it as in the following example, where the form is:
 j> (lambda (...) (...) (...))

(lambda (params) (form1) (form2) ... (formn))

is same as

(lambda (params)
    (progn (form1)
           (form2)
            ..
           (formn))

progn evaluates all forms 1..n, but returns only results of formn, hence the 
name progn.

 j> I don't know "function" in the example either.

lambda is shorthand macro that call function special op with 
lambda-expression, exactly as below, so it's not necessary to call function, 
but you can call if you want to.

 j> (add-hook 'asm-mode-hook
 j>       (function
 j>        (lambda ()
 j>             (make-local-variable 'compile-command)
 j>      (setq compile-command
 j>                    (concat "make -k -e EXECUTABLE="
 j>                    (file-name-sans-extension
 j>                          (file-name-nondirectory buffer-file-name)))
 j>                ))))

so it first calls make-local-variable, then it calls setq and returns it's 
result.

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"People who lust for the Feel of keys on their fingertips (c) Inity") 
From: Thomas A. Russ
Subject: Re: Basic question
Date: 
Message-ID: <ymifyep5cbv.fsf@sevak.isi.edu>
"jronald" <·········@163.com> writes:

> Is "lambda" a key word in lisp?
> The form with it I usually see is as below
> (lambda (p0 p1 ...) e)
> 
> I can't understand it as in the following example, where the form is:
> (lambda (...) (...) (...))
> I don't know "function" in the example either.
> 
> 
> sample code:
> 
> (add-hook 'asm-mode-hook
>       (function
>        (lambda ()
>             (make-local-variable 'compile-command)
>      (setq compile-command
>                    (concat "make -k -e EXECUTABLE="
>                    (file-name-sans-extension
>                          (file-name-nondirectory buffer-file-name)))
>                )))) 
> 

Well, the example suggests that the OP is looking for Emacs lisp help
rather than Common Lisp help.  (Not that it matters about the main
question).

Anyway, LAMBDA is used to introduce an anonymous function.  The first
list following the lambda is the list of arguments (formal parameters)
to the anonymous function.  The remaining forms are the body of the
function and are executed sequentially.  The value of the last form is
returned.  If there are multiple forms, then any forms preceding the
last are executing for side effects only.

FUNCTION is used to tell the lisp system that the following form is to
be handled like a function.  In Common Lisp this is no longer necessary,
but it is likely to still be required in Emacs Lisp.

In the example you give, the hook function that is being added takes no
arguments, and executes a form that first makes sure that the symbol
COMPILE-COMMAND name a local variable (I'm a bit rusty at Emacs lisp,
but I presume this makes it buffer-local), and then sets the value of
the variable to a particular invocation of the make function.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Lars Brinkhoff
Subject: Re: Basic question
Date: 
Message-ID: <85bqpcjmwy.fsf@junk.nocrew.org>
···@sevak.isi.edu (Thomas A. Russ) writes:
> FUNCTION is used to tell the lisp system that the following form is to
> be handled like a function.  In Common Lisp this is no longer necessary,
> but it is likely to still be required in Emacs Lisp.

It was required in Emacs 18, but not since sometime in early 19.x:

1992-05-13  Jim Blandy  (····@pogo.cs.oberlin.edu)

        * subr.el (lambda): Define this as a macro which wraps the lambda
        expression in a (function ...) quoter.  This means that you don't
        need to write out the cursed ``function'' any more.