Q: When, if ever, is it useful to sharp-quote a lambda
, and when, if ever, must we not sharp-quote a lambda
?
People use lambda
s in three ways:
- plain:
(lambda (x) x)
- quoted:
'(lambda (x) x)
- sharp-quoted:
#'(lambda (x) x)
This SO thread discusses the three types, this SO thread explains why not to quote (NB: not sharp-quote) lambda
s, and this SO thread also discusses the distinctions between quoting and sharp-quoting.
Now, the manual node on anonymous functions and the docstring for lambda
note that lambda
s are self-quoting:
A call of the form
(lambda ARGS DOCSTRING INTERACTIVE BODY)
is self-quoting; the result of evaluating the lambda expression is the expression itself. The lambda expression may then be treated as a function...
So, it appears that (lambda (x) x)
and #'(lambda (x) x)
are equivalent, but '(lambda (x) x)
is not (most importantly, when byte-compiling).
It looks like one would rarely want to quote a lambda
, but it's unclear to me when, if ever, we should, or should not, sharp-quote:
- Is sharp-quoting a
lambda
simply a stylistic choice, or are there circumstances in which sharp-quoting is actually useful? - Are there circumstances in which we must not sharp-quote a
lambda
, that is, when doing so would alter the meaning of the code?