Can someone please explain this?
lisptips.com/post/31567007407/putting-the-r-i...Posted Jan 22, 2014, 1:33 PM UTC
Posted Jan 22, 2014, 1:33 PM UTC
It may help to understand that the reader expands reader-macros like #' and ' even when they are not in places that are evaluated for a value.
Ok, I got it. I thought #'x calls x, didn't realize it expands to (function x). Thanks.
It expands to
(let ((function 42)) ...)
Figure the rest yourself.
Trying (function 42), gives me "FUNCTION: 42 is not a function name; try using a symbol instead". I know that #' is for functions. Looking at the hyperspec, this:
http://www.lispworks.com/documentation/HyperSpec/Body/t_fn.htm
kind of seems like it is what is happening/being used(?), but I don't understand what is going on.
It doesn't matter what FUNCTION does, start with LET. LET creates a binding for FUNCTION, so that it evaluates to 42 inside of this LET.
#'aaa is a reader macro that expands to (function aaa)
(something . (foo bar)) is the same as (something foo bar), because of how lists are constructed from cons cells.
Aha. I thought #'x calls x, didn't realize it expands to (function x). Ok, I got it. Thanks :-)
..Heh, rereading my reply, you actually specifically said that it expands to (let ((function 42)) ... ,but because of my above misconception, I was totally blind of the existance of let, and was seeing "call 42" instead of "we now have this symbol called 'function' here.
The let assigns the value of 42 to the symbol 'function'. Is there something you don't get in the excellent explanation in the blog comments?
[deleted]
First you need to see what the reader creates:
or
Does that help?
#' and . are already doing something during parsing by the reader - see above.
Note though, that this is a rather useless 'tip' - one should not use this LET + #' effect in code. This use of the dot-notation is sometimes, seen, though.
Ok, I got it. I thought #'x calls x, didn't realize it expands to (function x). Thanks.
It is better to think of
#'xas being read as(function x)instead of expanding to(function x). In Common Lisp, whose reader is a pretty complicated thing, it is good to start remembering that there is a distinct phasereadingbefore macroexpansion or other evaluation takes place.Great point. Thanks.