Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>The LAMBDA expression</strong></p> <p><code>(lambda ...)</code> is considered to be a <em>lambda expression</em> only in certain places, like the <code>function</code> form or as the head of a function call. Lambda expressions are not evaluated.</p> <pre><code>(function ; special operator FUNCTION (lambda () 'foobar)) ; &lt;- this is a lambda expression ( ; a function call (lambda (foo) foo) ; &lt;- this is a lambda expression 'bar ; argument ) </code></pre> <p>But here <code>(lambda ...)</code> is a macro form and not a lambda expression:</p> <pre><code>(funcall ; calling a function via funcall (lambda (foo) foo) ; this is not a lambda expressions, but the macro lambda ; as all arguments to FUNCALL it will be ; macro expanded and evaluated ; it expands to (function (lambda (foo) foo)) 'bar) ; argument </code></pre> <p><strong>The LAMBDA macro</strong></p> <p><a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_lambda.htm" rel="nofollow noreferrer">LAMBDA</a> is a macro. It expands <code>(lambda ...)</code> to <code>(function (lambda ...))</code>, which is the equivalent of <code>#'(lambda ...))</code>.</p> <pre><code>CL-USER &gt; (macroexpand '(lambda (foo) foo)) (FUNCTION (LAMBDA (FOO) FOO)) </code></pre> <p>The macro saves you a bit of writing/reading, that's all. In the first version of Common Lisp (CLtL1) there was no <code>LAMBDA</code> macro. It has been added later and is now a part of <em>ANSI Common Lisp</em>,</p> <p><strong>The FUNCTION special operator</strong></p> <p><a href="http://www.lispworks.com/documentation/HyperSpec/Body/s_fn.htm#function" rel="nofollow noreferrer">FUNCTION</a> is a special operator. It expects a function name or a <em>lambda expression</em>. Thus the name or the <em>lambda expression</em> are not evaluated. In fact <em>lambda expressions</em> can't be evaluated at all. Inside <code>FUNCTION</code>, the <em>lambda expression</em> is <strong>not</strong> a macro form and thus will <strong>not</strong> be expanded again. The purpose of <code>FUNCTION</code> is to return the corresponding function object which is denoted by the name or by the <em>lambda expression</em>. It returns the function object as a value. With this special operator one can access the function object from global functions and lexical functions.</p> <p>The <code>FUNCTION</code> operator is necessary in Common Lisp, because it has separate namespaces for values, functions and a few other things. It as a so-called <em>Lisp-2</em> or even <em>Lisp-n</em>, with two or more namespaces.</p> <p><strong>Lambda expressions in function position in a function form</strong></p> <p><code>((lambda (foo) foo) 10)</code> is supported by built-in syntax for Common Lisp. See <a href="http://www.lispworks.com/documentation/HyperSpec/Body/03_ababd.htm" rel="nofollow noreferrer">Lambda Forms</a>.</p> <p><strong>Confusing</strong></p> <p>This is all logical, but confusing. Don't worry you are not alone, but in practice it's not a big deal.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload