I'm familiar with Emacs Lisp, but not Common (or any other) Lisp. Some Lisp programmers suggest (e.g. A basic function for emacs) that it's good to use #'
in front of function arguments in Lisp code. For example:
(mapc #'my-fun '(1 2 3))
In Emacs Lisp, I believe that this is equivalent to
(mapc 'my-fun '(1 2 3))
From the elisp manual, section 12.7.
The read syntax
#'
is a short-hand for usingfunction
. The following forms are all equivalent:(lambda (x) (* x x)) (function (lambda (x) (* x x))) #'(lambda (x) (* x x))
and the help for function
function is a special form in
eval.c
.(function ARG)
Like
quote
, but preferred for objects which are functions. In byte compilation,function
causes its argument to be compiled.quote
cannot do that.
So it seems like a potential optimization, but no more. Moreover, coming from an ML/Haskell background, it seems strange to treat a function differently from any other data.
Question:
Do you agree that #'
should be used in emacs-lisp
function arguments?
(A brief explanation of why they're needed in Common Lisp would be great as well.)
Notes:
I thought it may read a different cell when the #'
is omitted (value vs function). But
this seems wrong because the documentation for function
doesn't say anything about grabbing the function cell. This is achieved by using symbol-function
.
Related questions are
- The #' in common lisp
- Writing lambda expressions in common lisp
- Why #' is used before lambda in Common Lisp?
but they seem to suggest that the #'
is unnecessary, at least in lambdas.