Fork me on GitHub
#beginners
<
2015-09-09
>
escherize10:09:03

Hi, I'm doing 4clojure problem 118, and have this so far:

(fn mm [f coll]
   (lazy-seq
    (when (not= [] coll)
      (cons (f (first coll))
            (mm f (rest coll))))))

escherize10:09:20

which works, but it's failing out on the third test

escherize10:09:53

i understand if you are returning a collection, you need to hold onto the head. I'm not sure why this would be so slow, though.

escherize10:09:11

(the error is Execution timed out.)

roberto13:09:44

@escherize: you might want to look at how to do tail calls with clojure. Have a look at loop & recur.

paulb19:09:33

@escherize if you change (not= [] coll) to (not (empty? coll)) it works. I am not sure why this is.