ClojureScript

get-in throws exception when key-list contains key that doesn't satisfy ILookup

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major 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))))

Activity

David Nolen made changes -
Field Original Value New Value
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))))
(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.

{code}
--------

(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))))
{code}
Hide
David Nolen added a comment -

Yes patch welcome.

Show
David Nolen added a comment - Yes patch welcome.
David Nolen made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: