[CLJ-1282] The quote special form should throw an exception if passed more than one form to quote Created: 23/Oct/13 Updated: 09/Dec/13
|Affects Version/s:||Release 1.5|
|Reporter:||Howard Lewis Ship||Assignee:||Unassigned|
Quote currently ignores all but the first argument. In the case of being called accidentally with multiple values, it should throw an exception specifying the error.
------- Original: --------
Every once in a while, you can just go down the rabbit hole.
I had an errant expression in my code:
One would think this would work; it certainly would if the key was a keyword and not a symbol.
One would expect this to expand to:
however, the reader is involved, so it is as if the source were:
which expands to:
... hilarity ensues! Because quote currently ignores extra parameters, my code gets the quoted value '(clojure.core/-> message get-message-values) rather than the expected string from the map; this shifts us from the "there's a bug in my code" to "the nature of reality is broken".
The correct expression is:
This took quite a while to track down; if the special form checked that it was passed exactly one form to quote and threw an exception otherwise, I think I would have caught this much earlier. It could even identify the expression it is quoting, which would provide a lot better understanding of where I went wrong.
|Comment by Howard Lewis Ship [ 23/Oct/13 2:02 PM ]|
Sorry, can't edit the description now to correct the formatting errors.
|Comment by Howard Lewis Ship [ 24/Oct/13 6:09 PM ]|
I just wanted to point out that your description is shorter, but makes it appear that such a use is unlikely and therefore unimportant; the detail of my description is to point out a reasonable situation where something explicable, but completely counterintuitive and confusing, does occur.
|Comment by Alex Miller [ 24/Oct/13 8:28 PM ]|
That's why I left the original in there too.
|Comment by Gary Fredericks [ 09/Dec/13 7:07 AM ]|
(quote) currently returns nil. Do we have an opinion about that?
|Comment by Gary Fredericks [ 09/Dec/13 9:32 AM ]|
Attached p1, which throws an IllegalArgumentException (wrapped in a CompilerException of course) for anything but 1 arg, and includes the number of args that were passed.
I can't think of any reason why (quote) would be useful, so I decided to throw on that too. Very easy to change of course.
Also added a test that (eval '(quote 1 2 3)) throws.