leonoel / missionary

A functional effect and streaming system for Clojure/Script
Eclipse Public License 2.0
620 stars 25 forks source link

Performance warning - case has int tests, but tested expression is not primitive. #72

Open ggeoffrey opened 1 year ago

ggeoffrey commented 1 year ago

This warning shows up when *warn-on-reflection* is set to true.

It comes from amb:

(defmacro
  ^{:arglists '([& forms])
    :doc "In an `ap` block, evaluates each form sequentially and returns successive results."}
  amb
  ([] `(?> none))
  ([form] form)
  ([form & forms]
   (let [n (inc (count forms))]
     `(case (?> (seed (range ~n)))                          ; <- missing `int` cast
        ~@(interleave (range) (cons form forms))))))

(case (int (?> (seed (range ~n)))) …) fixes the issue

The same applies to amb=.