Entries from 2010-04-10 to 1 day

ClojureでmapAccumL

こっちはスタックオーバフローする。lazy-seq意味なし。 user> (defn map-accum-l [f s ls] (if (empty? ls) [s []] (let [[ss y] (f s (first ls)) [sss ys] (map-accum-l f ss (rest ls))] [sss (lazy-seq (cons y ys))]))) #'user/map-accum-l user> (map…

Clojureでscanl

lazy-seqはこういうときに使えるのか。 user> (defn scanl [f q ls] (lazy-seq (cons q (if (empty? ls) '() (scanl f (f q (first ls)) (rest ls)))))) #'user/scanl user> (scanl + 0 (range 0 9)) (0 0 1 3 6 10 15 21 28 36) user> (take 10 (scanl + 0 …