bsless / clj-fast

Unpredictably faster Clojure
Eclipse Public License 2.0
234 stars 1 forks source link

not-found arities of get and get-in #24

Closed yuhan0 closed 3 years ago

yuhan0 commented 3 years ago

Why does the inline/get macro take [m k & nf] arguments? Having more than one not-found argument in the expanded (clojure.lang.RT/get ..) form seems to be clearly an error.

Similarly, is there a reason why inline/get-in does not take a not-found argument?

I added one like so:

(defmacro get-in
  "Like `get-in` but faster and uses code generation.
  `ks` must be either vector, list or set."
  ([m ks]
   {:pre [(u/simple-seq? ks)]}
   (lens/get (fn [k] `(get ~k)) m ks))
  ([m ks nf]
   {:pre [(u/simple-seq? ks)]}
   (let [g (gensym)]
     `(let [~g ~nf]
        ~(lens/get (fn [k] `(get ~k ~g)) m ks)))))
bsless commented 3 years ago

Nice solution! Do I have your permission to add it?

yuhan0 commented 3 years ago

Sure, go ahead! But I'd rather not be mentioned in the comments, thanks :)