Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In Common Lisp <code>LAMBDA</code> is two different things: a macro and a symbol which can be used in a LAMBDA expression.</p> <p>The LAMBDA expression:</p> <pre><code>(function (lambda (x) (foo x))) </code></pre> <p>shorter written as</p> <pre><code>#'(lambda (x) (foo x)) </code></pre> <p>An applied lambda expression is also valid:</p> <pre><code>((lambda (x) (+ x x)) 4) </code></pre> <p>Above both forms are part of the core syntax of Common Lisp.</p> <p>Late in the definition of Common Lisp a macro called <code>LAMBDA</code> has been added. Confusingly enough, but with good intentions. ;-) It is documented as <a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_lambda.htm" rel="noreferrer">Macro LAMBDA</a>.</p> <pre><code>(lambda (x) (+ x x)) </code></pre> <p>expands into</p> <pre><code>(function (lambda (x) (+ x x)) </code></pre> <p>It makes Common Lisp code look slightly more like Scheme code and then it is not necessary to write</p> <pre><code>(mapcar #'(lambda (x) (+ x x)) some-list) </code></pre> <p>With the <code>LAMBDA</code> macro we can write</p> <pre><code>(mapcar (lambda (x) (+ x x)) some-list) </code></pre> <p>Your example fails because</p> <pre><code>((my-lambda (x) (* x x)) 2) </code></pre> <p>is not valid Common Lisp syntax.</p> <p>Common Lisp expects either</p> <ul> <li>a data object</li> <li>a variable</li> <li>a function call in the form <code>(function args...)</code></li> <li>a function call in the form <code>((lambda (arglist ...) body) args...)</code></li> <li>a macro form like <code>(macro-name forms...)</code></li> <li>a special form using one of the built-in special operators like <code>FUNCTION</code>, <code>LET</code>, ... defined in the list of <a href="http://www.lispworks.com/documentation/HyperSpec/Body/03_ababa.htm#clspecialops" rel="noreferrer">special operators</a> in Common Lisp</li> </ul> <p>As you can see a syntax of</p> <pre><code>((macro-name forms...) forms...) </code></pre> <p>is not a part of Common Lisp.</p> <p>It is possible to read the character <code>λ</code> as <code>LAMBDA</code>:</p> <pre><code>(defun λ-reader (stream char) (declare (ignore char stream)) 'LAMBDA) (set-macro-character #\λ #'λ-reader) </code></pre> <p>Example:</p> <pre><code>CL-USER 1 &gt; ((λ (x) (* x x)) 3) 9 CL-USER 2 &gt; '(λ (x) (* x x)) (LAMBDA (X) (* X X)) </code></pre>
    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