Share your thoughts in the 2024 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in Errors by

('+ 1 2) ;; return 2 because it is treated as (get 1 '+ 2)

Whilst this is "consistent" once you know the lookup behavior, it's confusing for Clojure newbies and it seems to be a non-useful behavior.

Proposal: modify Keyword.invoke() and Symbol.invoke() to restrict first Object argument to instanceof ILookup, Map or IPersistentSet (or null) so that the "not found" behavior doesn't produce non-intuitive behavior.

This should track CLJ-1107.

by
Ooh, I ran into this the other day, caught me off guard. An error message like the proposed patch would have been very helpful.
by
I would be very concerned that making this existing, working, consistent behavior an error would break existing code (regardless of how strange that code might be considered).
by
Having thought about it, you're right that this behavior is consistent and changing it would be not only a breaking change but a pretty deep reversal of expectations.

3 Answers

0 votes
by

Comment made by: zjhmale

a patch to fix this issue

0 votes
by

Comment made by: zjhmale

for now

user=> ('+ 1 2)
IllegalArgumentException class java.lang.Long is not lookupable: clojure.lang.Symbol.throwNotLookupable (Symbol.java:127)
user=> (:+ 1 2)
IllegalArgumentException class java.lang.Long is not lookupable: clojure.lang.Keyword.throwNotLookupable (Keyword.java:103)

and everything else works fine

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-969 (reported by seancorfield)
...