Hello, everyone. I'm writing some code that utilizes the lazy sequence. But
I found something strange. Here is how:

The code is like:

(first (filter some-expensive-io urls))

The code is aimed to find the first result of the operations on the urls
that is not nil. However, it seems that the io operations are executed once
more than needed. As the operations are slow, one more round increases the
overhead dramatically.

Then I tested other pieces of code, such as:

(first (filter #(when (> % 1) (println %) %) (range)))

It prints out:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

and returns: 2

So why the lazy sequence is realized more than it is needed? Could I
enforce the laziness and save unnecessary operation?


Thanks,
Bruce Li

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to