> But shouldn't it give me 9 items without hanging when I ask for 10 or
> more as in the first case?

No.

take returns a lazy sequence. The printer is trying to realize it in  
order to print it. It can't be completely realized until it's taken  
ten elements (at which point it's done, by definition).

In realizing the sequence, the first nine items are collected. take  
wants one more. It tries to fetch it from the filtered lazy-seq.

The filtered seq gets 10 from the iterate lazy-seq, which doesn't pass  
the filter. It gets 11, which doesn't pass the filter...

Neither filter nor take know to abandon their attempt. That's how this  
works. Imagine if you wrote:

user=> (take 10 (filter #(or (= 1000 %) (< % 10)) (iterate inc 1)))
(1 2 3 4 5 6 7 8 9 1000)


It just keeps on going until it's found ten elements.

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

Reply via email to