3 ms·
Oh, I see. In that case, I was a little confused by the following: CL-USER> (remove-if-not #'evenp '(1 2 3 4 5 6 7 8 9 10)) (2 4 6 8 10) The author explai
by chris_wot 10y ago
Oh, I see. In that case, I was a little confused by the following:
CL-USER> (remove-if-not #'evenp '(1 2 3 4 5 6 7 8 9 10))
(2 4 6 8 10)
The author explained what #'evenp did (FUNCTION '(1 2 3 4 5 6 7 8 9 10)) but not that '(1 2 3 4 5 6 7 8 9 10) is just (1 2 3 4 5 6 7 8 9 10).
In other words, the above evaluates to:
(FUNCTION evenp (1 2 3 4 5 6 7 8 9 10))
Or didn't explain it unless, of course, I missed a bit :-)
- bluefox 10y agoYou can see how an expression is read this way: (defun how-is-it-read? (string) (write-to-string (read-from-string string) :pretty nil)) ==> HOW-IS-IT-READ? (how-is-it-read? "#'foo") ==> "(FUNCTION FOO)" (how-is-it-read? "(remove-if-not #'evenp '(1 2 3 4 5 6 7 8 9 10))") ==> "(REMOVE-IF-NOT (FUNCTION EVENP) (QUOTE (1 2 3 4 5 6 7 8 9 10)))" You can see that this does not match your expectation. Are you actually trying to type that code and evaluate it at a Lisp listener? If not, you should. Now, FUNCTION is a special operator that in this case returns the function named EVENP. QUOTE is a special operator that just returns the object it is passed. So REMOVE-IF-NOT will get called with two arguments: the function named EVENP, and a list of integers from 1 to 10.