3 ms·
Good point. That is possible, albeit with a modest overhead. The overhead would be irrelevant except that state machines get used in very performance critical
by btilly 17y ago
Good point. That is possible, albeit with a modest overhead. The overhead would be irrelevant except that state machines get used in very performance critical ways, such as inside a regular expression engine. But possibly Clojure isn't the right language if you care about performance that much.
Incidentally I'd be shocked if trampoline was a special form rather than a function. I'm not sure what type a function is (I don't use clojure nor is it installed here), but it should be possible to implement it something like this:
(defn trampoline [f]
(if (eq? (type f) 'function')
(recur (f))
f))
- spuz 17y agoIndeed, Clojure's trampoline is a function: (defn trampoline ([f] (let [ret (f)] (if (fn? ret) (recur ret) ret))) ([f & args] (trampoline #(apply f args))))