FAU wrote:I've been reading a little bit in LOL. Please look at this:
;;; From LOL, chapter 4, page 80.
(defvar to-splice '(B C D))
`(a ,.to-splice e)
to-splice ; => (B C D E)
Here apparently a literal list is being modfied and we all know that the results are undefined. Either this is a bad example or I'm completely missing something here.
Paul wrote:Presumably you're supposed to be typing this at the REPL, so there is no problem (the results are perfectly well defined as long as you don't file-compile it).
In some sense it's a "bad example", in that you don't want to teach bad habits...but on the other hand, I think it's better to teach people to understand how things really work [...]
Kompottkin wrote:Paul wrote:Presumably you're supposed to be typing this at the REPL, so there is no problem (the results are perfectly well defined as long as you don't file-compile it).
“The consequences are undefined if literal objects (including quoted objects) are destructively modified.” (CLHS, Special Operator QUOTE)
What you're probably thinking of is the fact that literals may be coalesced only when doing file compilation. However, literals may never be destructively modified, regardless of whether or not they have been coalesced.
Paul wrote:It's not just a matter of coalescing it with other similar lists, the file compiler can do other things, like putting it in read-only memory...but the REPL can never do such things
so in fact you can modify "literals"; it's perfectly well defined
the only thing that matters is what QUOTE does, and that's fully specified
Users browsing this forum: Google [Bot] and 5 guests