<< Back to previous view

[CLJS-458] get-in throws exception when key-list contains key that doesn't satisfy ILookup Created: 15/Jan/13  Updated: 27/Jul/13  Resolved: 26/Jan/13

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Frank Siebenlist Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: None
Environment:

clojurescript r1552



 Description   

(get-in {:a {:b 1}} [:a :b :c] :nothing-there)

cljs throws exception "Error: No protocol method ILookup.-lookup defined for type number: 1"
clj returns :nothing-there

Following snippet contains an additional (satisfies? ILookup m) test to end iteration and return no-value.
If solution looks ok, I can provide a patch.

--------

(defn get-in*
  "Returns the value in a nested associative structure,
  where ks is a sequence of keys. Returns nil if the key is not present,
  or the not-found value if supplied."
  {:added "1.2"
   :static true}
  ([m ks]
     (reduce get m ks))
  ([m ks not-found]
     (loop [sentinel lookup-sentinel
            m m
            ks (seq ks)]
       (if ks
         (if-not (satisfies? ILookup m)
           not-found
           (let [m (get m (first ks) sentinel)]
             (if (identical? sentinel m)
               not-found
               (recur sentinel m (next ks)))))
         m))))


 Comments   
Comment by David Nolen [ 18/Jan/13 3:26 PM ]

Yes patch welcome.

Comment by David Nolen [ 26/Jan/13 11:15 AM ]

fixed, http://github.com/clojure/clojurescript/commit/e8d20229ee87747e3012ac97b5b7006d3703a305

Generated at Thu Sep 18 17:02:29 CDT 2014 using JIRA 4.4#649-r158309.