Page 6 of 6

Re: Experience of Learning Lisp

Posted: Wed Jul 22, 2009 8:07 am
by gugamilare
Perhaps this is not a so hypothetical example as I said. It looks like many implementations do (or did) collapse their constant data when compiling files.

I found something interesting at this X3J13 issue.

According to quote in hyperspec, it looks like your example is unportable code, since the spec clearly says:
The consequences are undefined if literal objects (including quoted objects) are destructively modified.
You code is quoted, therefore it is considered to be literal, even though it comes from non-constant data. The spec also states that compile-file is allowed to coalesce or copy constant data. The same is not true to eval or compile, but compile-file could be used to implement the REPL, therefore potentially bringing those issues to the REPL, but now this is a hypothetical example, since it is stupid not to use compile or eval instead. And, even though the specification restricted the copying and coalescing of data by the compile function, Kent Pitman said that at least MCL coalesced data when compiling code. But that was back in 2001, now there is no MCL anymore, but I think this justifies what he was trying to say.

Anyway, as I usually think, the REPL is an informal tool, you can and should do with it whatever you want to do without any harm with an implementation you trust (for instance, SBCL, which would warn you when you are doing something potentially dangerous). If something goes wrong, you can find the error, learn from it and try again in a different way or report it. But when writing files which you will distribute, you should to be careful with constant data.

Re: Experience of Learning Lisp

Posted: Wed Jul 22, 2009 7:15 pm
by Paul
gugamilare wrote:
Paul wrote:And if I type

Code: Select all

(defvar *foo* (list 1 2 3))

(defvar *list* (quote #.*foo*))
the QUOTE can't distinguish between what it sees now and what it saw in your example, so it moves my *foo* list into read-only space....and fails to comply with the standard!
Yes, you are probably right that no one would do this. As a hypothetical example, though, the implementation could have added some tags to the value of *foo* when expanding #.*foo*, and quote would see that tag and wouldn't move it into read-only space.
Then (EVAL (LIST (QUOTE QUOTE) *FOO*) will screw it up...etc. Anyway, the issue has nothing whatsoever to do with QUOTE: you can type most literals without QUOTE (e.g., strings, vectors, pathnames, ...)

Re: Experience of Learning Lisp

Posted: Wed Jul 22, 2009 7:16 pm
by Paul
gugamilare wrote:Perhaps this is not a so hypothetical example as I said. It looks like many implementations do (or did) collapse their constant data when compiling files.
Yes; compile-file is a different issue (I already mentioned that).
but compile-file could be used to implement the REPL
No it can't. That would destroy object identity.