Details
-
Type:
Defect
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
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))))
Yes patch welcome.