Re: arity-3 `iterate`

2015-11-16 Thread Ben Wolfson
ncomp would be faster if it's implemented a la exponentiation by squaring. On Mon, Nov 16, 2015 at 12:55 PM, Ben Wolfson wrote: > If you rearrange the arguments of your proposed three-argument iterate: > > (defn iterate > ... > ([f n x] >(if (zero? n) > x > (recur f (f x) (dec

Re: arity-3 `iterate`

2015-11-16 Thread Ben Wolfson
If you rearrange the arguments of your proposed three-argument iterate: (defn iterate ... ([f n x] (if (zero? n) x (recur f (f x) (dec n it supports partial application of the multiply-composed function to different arguments more easily, which suggests redefinition as: (def

arity-3 `iterate`

2015-11-16 Thread Jason Felice
I *frequently* see: (nth (iterate foo bar) n) And: (->> (iterate foo bar) (drop n) first) I've also coded this in `avi` after being surprised no such thing exists: (defn n-times [thing n a-fn] (reduce (fn [thing n] (a-fn thing)) thing (range n))) (which is kind of