Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>#'foo</code> is an <a href="http://www.lispworks.com/documentation/lw51/CLHS/Body/02_dhb.htm" rel="nofollow noreferrer">abbreviation</a> for <code>(function foo)</code> by the reader.</p> <p>In CL, there are several different namespaces, <code>#'foo</code> or <code>(function foo)</code> will return the <i>functional value</i> of <code>foo</code>.</p> <p>You may want to <a href="https://www.startpage.com/do/metasearch.pl?query=Lisp-1%20vs.%20Lisp-2" rel="nofollow noreferrer">search for "Lisp-1 vs. Lisp-2"</a>, check other <a href="https://stackoverflow.com/questions/1020968/separate-namespaces-for-functions-and-variables-in-common-lisp-versus-scheme">Stackoverflow questions</a>, or read an <a href="http://www.dreamsongs.com/Separation.html" rel="nofollow noreferrer">old article py Pitman and Gabriel</a> in order to learn more about the concept of multiple namespaces (also called <i>slots</i> or <i>cells</i> of symbols).</p> <p>The reason that, in the case of lambda the <code>#'</code> may be omitted is, that this is a macro in CL, which expands thusly (taken from the <a href="http://www.lispworks.com/documentation/lw51/CLHS/Body/m_lambda.htm" rel="nofollow noreferrer">Hyperspec</a>):</p> <pre><code>(lambda lambda-list [[declaration* | documentation]] form*) == (function (lambda lambda-list [[declaration* | documentation]] form*)) == #'(lambda lambda-list [[declaration* | documentation]] form*) </code></pre> <p><code>#'</code> may still be used for historic reasons (I think that in Maclisp <code>lambda</code>s didn't expand to the function form), or because some people think, that "tagging" lambdas with sharpquotes may make the code more readable or coherent. There may be some special cases in which this makes a difference, but in general, it doesn't really matter which form you choose.</p> <p>I guess you can think of it like this: <code>(function (lambda ...))</code> returns the function <code>(lambda ...)</code> creates. Note that <code>lambda</code> in the CL Hyperspec has both <a href="http://www.lispworks.com/documentation/HyperSpec/Body/a_lambda.htm" rel="nofollow noreferrer">a macro AND a symbol entry</a>. From the latter:</p> <blockquote> <p>A lambda expression is a list that can be used in place of a function name in certain contexts to denote a function by directly describing its behavior rather than indirectly by referring to the name of an established function.</p> </blockquote> <p>From the <a href="http://clhs.lisp.se/Body/s_fn.htm" rel="nofollow noreferrer">documentation</a> of <code>function</code>:</p> <blockquote> <p>If name is a lambda expression, then a lexical closure is returned.</p> </blockquote> <p>I think the difference is also related to calling lambda forms like this: <code>((lambda ...) ...)</code> where it is treated as a form to be evaluated, vs. <code>(funcall #'(lambda ...) ...)</code>. If you want to read more on the topic, there is a <a href="http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/e842449e3bac2555/07d63dde2c79d02f?#07d63dde2c79d02f" rel="nofollow noreferrer">c.l.l thread</a> about it.</p> <p>Some quotes from that thread:</p> <blockquote> <p><code>(lambda (x) ...</code> by itself is just some unquoted list structure. It is its appearance as an argument to the FUNCTION special form <code>(function (lambda (x) ...</code> that causes the function object to exist</p> </blockquote> <p>and:</p> <blockquote> <p>It's also compounded by the fact that the LAMBDA macro was a rather late addition the ANSI Common Lisp, so all of the really old guys (i.e., like me) learned their lisp when you needed to supply the #' to the lambda expression in the mapping functions. Otherwise the non-existent lambda function would be invoked.</p> <p>The macro addition changed that, but some of us are too set in our ways to want to change.</p> </blockquote>
 

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