Clojure

Symbol/keyword implements IFn for lookup but a non-collection argument produces non-intuitive results

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:

Description

('+ 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.

Activity

Hide
zjhmale added a comment -

a patch to fix this issue

Show
zjhmale added a comment - a patch to fix this issue
Hide
zjhmale added a comment -

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

Show
zjhmale added a comment - 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

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: