diff --git a/jolt-core/clojure/core/20-coll.clj b/jolt-core/clojure/core/20-coll.clj index 91b30ab..d201fda 100644 --- a/jolt-core/clojure/core/20-coll.clj +++ b/jolt-core/clojure/core/20-coll.clj @@ -209,16 +209,8 @@ (defn rationalize [x] x) ;; trampoline: repeatedly calls f with args until a non-function result. -(defn trampoline - ([f] (trampoline f (f))) - ([f & args] - (let [ret (apply f args)] - (if (fn? ret) - (recur ret) - ret)))) ;; rand-int: random integer in [0, n). Uses Janet math/random. -(defn rand-int [n] (math/floor (* (math/random) n))) ;; Eager dedupe of consecutive equal elements (Jolt has no transducer arity yet). (defn dedupe [coll] diff --git a/src/jolt/core.janet b/src/jolt/core.janet index 19b4c03..3eb75be 100644 --- a/src/jolt/core.janet +++ b/src/jolt/core.janet @@ -1405,6 +1405,10 @@ (defn core-rand-int [n] (math/floor (* (math/random) n))) +(defn core-trampoline [f & args] + (var result (apply f args)) + (while (function? result) (set result (result))) + result) (def core-format (fn [fmt & args] (string/format fmt ;args))) # ============================================================