Hello,

I played a bit with Fibonacci again. The slow and inefficient way ;-)

(defn fib0 [n] (if (< n 1) 1 (+ (fib0 (- n 1)) (fib0 (- n 2)))))

user=> (time (fib0 35))
"Elapsed time: 20874.18345 msecs"
24157817

I use (set! *print-length* 10) and tried some mapping:

user=> (time (map fib0 (iterate inc 1)))
"Elapsed time: 0.913524 msecs"
(2 3 5 8 13 21 34 55 89 144 ...)

Everything fine.
Now what puzzles me:

user=> (time (map fib0 (range 100)))
"Elapsed time: 1.248203 msecs"

The time is printed "immediately", but the result waits about 8
seconds to print!

(1 2 3 5 8 13 21 34 55 89 ...)

Can you tell whats happening here? Especially comparing to the
(iterate inc 1) version ..

Thank you and regards, alux

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to