Yes, chunked sequences explain the behaviour, look:

1:1 user=> (set! *print-length* 10)
10
1:2 user=> (defn fib0
  [n]
  (let [fib (fn fib [n] (if (< n 1) 1 (+ (fib (- n 1)) (fib (- n 2)))))]
    (println (str "fib0[" n "]"))
    (fib n)))
#'user/fib0
1:7 user=> (time (map fib0 (iterate inc 0)))
"Elapsed time: 0.294021 msecs"
(fib0[0]
fib0[1]
1 fib0[2]
2 fib0[3]
3 fib0[4]
5 fib0[5]
8 fib0[6]
13 fib0[7]
21 fib0[8]
34 fib0[9]
55 fib0[10]
89 fib0[11]
...)
1:8 user=> (time (map fib0 (range 100)))
"Elapsed time: 0.881059 msecs"
(fib0[0]
fib0[1]
fib0[2]
fib0[3]
fib0[4]
fib0[5]
fib0[6]
fib0[7]
fib0[8]
fib0[9]
fib0[10]
fib0[11]
fib0[12]
fib0[13]
fib0[14]
fib0[15]
fib0[16]
fib0[17]
fib0[18]
fib0[19]
fib0[20]
fib0[21]
fib0[22]
fib0[23]
fib0[24]
fib0[25]
fib0[26]
fib0[27]
fib0[28]
fib0[29]
fib0[30]
fib0[31]
1 2 3 5 8 13 21 34 55 89 ...)
1:9 user=>


2010/3/19 alux <alu...@googlemail.com>:
> Meikel,
>
> you are right, I changed horses, uh, definitions inbetween. So the
> REPL interaction of my last response should read
>
> Clojure 1.1.0
> user=> (set! *print-length* 10)
> 10
> user=> (defn fib0 [n] (if (< n 1) 1 (+ (fib0 (- n 1)) (fib0 (- n
> 2)))))
> #'user/fib0
> user=> (time (map fib0 (range 100)))
> "Elapsed time: 1.979022 msecs"
> (1 2 3 5 8 13 21 34 55 89 ...)
> user=> (time (map fib0 (iterate inc 0)))
> "Elapsed time: 0.969677 msecs"
> (1 2 3 5 8 13 21 34 55 89 ...)
> user=>
>
> Despite this, the text I wrote seems still valid to me; note that I
> changed the start point for the iterate as response to your mail.
> Thats why now both starts with 0 as argument, and 1 as result. But the
> range one waits some five sec, the iterate doesnt.
>
> Sorry for the confusion. And thanks for the patience ;-)
>
> Kind regards, alux
>
> PS.: A correct Fibonacci sequence would use (< n 2) instead of (< n
> 1). Just to mention it.
>
> Meikel Brandmeyer schrieb:
>> Hi,
>>
>> On Mar 19, 1:39 pm, alux <alu...@googlemail.com> wrote:
>>
>> > Still, I dont believe.
>>
>> You should...
>>
>> >
>> > I get the same difference with
>> >
>> > user=> (time (map fib0 (range 100)))
>> > "Elapsed time: 1.916445 msecs"
>> >
>> > more than 5 seconds
>> >
>> > (0 1 1 2 3 5 8 13 21 34 ...)
>> >
>> > user=> (time (map fib0 (iterate inc 0)))
>> > "Elapsed time: 0.104203 msecs"
>> > (0 1 1 2 3 5 8 13 21 34 ...)
>>
>> How does this fit to following?
>>
>> > user=> (time (map fib0 (iterate inc 1)))
>> > "Elapsed time: 0.913524 msecs"
>> > (2 3 5 8 13 21 34 55 89 144 ...)
>>   ^^^
>>
>> The example you posted can't be. With the fib0 you posted you get:
>>
>> (fib0 0) => 1
>> (fib0 1) => (+ (fib0 0) (fib0 -1)) => (+ 1 1) => 2
>>
>> So what you posted above can't be true. At least not with the fib0 you
>> gave in your original post.
>>
>> Sincerely
>> Meikel
>
> --
> 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.
>

-- 
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