Re: #' and lambda



On 2006-02-10 18:04:02 +0000, Alan Crowe <alan@xxxxxxxxxxxxxxxxxxxxxxx> said:

Thank you all for your explanations.

so the reason this works:

(defun weird-2 (f list)
(reduce f list))

CL-USER 1 > (weird-2 #'+ '(1 2 3))
6
CL-USER 2 > (weird-2 (lambda (a b) (when (and a b) (+ a b))) '(1 2 3))
6
CL-USER 3 > (weird-2 #'(lambda (a b) (when (and a b) (+ a b))) '(1 2 3))
6

is because weird-2 just doesn't care where f comes from,
and because #' special cases (lambda...

But #' doesn't special case anything else, and that's
why:

(defun weird-3 (f list)
(reduce #'f list))

doesn't even compile (well, it does, but issues a warning).

But then
(defun weird-4 (list)
(flet ((f (a b)
(when (and a b)
(+ a b))))
(reduce #'f list)))

does compile, and work:
CL-USER 5 > (weird-4 '(1 2 3))
6

My head still hurts a bit :-(

I'll review all this tomorrow.

Many thanks to all
--
JFB

.