clojure: stack overflow over range -
i trying solve problem 60 @ 4clojure.com
my solution works last 2 cases fails first case in handling range.
here solution
(fn reds ([func lst](if (empty? lst) [] (reds func (first lst) (rest lst)))) ([func init lst](if (empty? lst) (println "hi") (concat [init] (reds func (func init (first lst)) (rest lst))))) )
i think because keep calling function on more terms of infinite list . how do better?
update : solved using lazy-seq
Comments
Post a Comment