Andy Piper <andy(a)xemacs.org> writes:
At 03:49 PM 2/24/00 -0800, Martin Buchholz wrote:
>This patch [as described in the Subject] was produced using `diff
>-w'. Functions will be properly indented at commit time.
But what does it mean? And why is it better.
#'(lambda ...) is the reader shorthand for (function (lambda ...)),
while '(lambda () is shorthand for (quote (lambda ...)).
In interpreted mode, they're equivalent. When compiled, the latter
instructs the byte-compiler to compile the lambda form. So
(mapcar '(lambda ...) somelist)
is slower[1] than
(mapcar #'(lambda ...) somelist)
To make the story just a bit more spicy, there's also the lambda macro
that is a shorthand for (function (lambda ...)). Thus my favorite
form of writing the above is:
(mapcar (lambda ...) somelist)
[1]
Actually, that's a lie. In the special case of map* functions, when
the byte-compiler finds that the argument is a constant list whose car
is the symbol `lambda', it compiles the list.
From bytecomp.el:
(defun byte-compile-funarg (form)
;; (mapcar '(lambda (x) ..) ..) ==> (mapcar (function (lambda (x) ..)) ..)
;; for cases where it's guaranteed that first arg will be used as a lambda.
(byte-compile-normal-call
(let ((fn (nth 1 form)))
(if (and (eq (car-safe fn) 'quote)
(eq (car-safe (nth 1 fn)) 'lambda))
(cons (car form)
(cons (cons 'function (cdr fn))
(cdr (cdr form))))
form))))