Curiousity with dorun

0 views
Skip to first unread message

mifrai

unread,
Feb 19, 2009, 1:18:43 AM2/19/09
to Clojure
In the definition of dorun:
(defn dorun
"When lazy sequences are produced via functions that have side
effects, any effects other than those needed to produce the first
element in the seq do not occur until the seq is consumed. dorun can
be used to force any effects. Walks through the successive nexts of
the seq, does not retain the head and returns nil."
([coll]
(when (and (seq coll) (or (first coll) true))
(recur (next coll))))
([n coll]
(when (and (seq coll) (pos? n) (or (first coll) true))
(recur (dec n) (next coll)))))

Why do we evaluate (or (first coll) true) instead of just calling it
after the when?

ie. (when (seq coll)
(first coll)
(recur (next coll))

I only bring this up because compiling with assert-if-lazy-seq=true
and running something like:
(doall (map range (repeat 0) (range 10)))
brings up a lazy seq exception.
Reply all
Reply to author
Forward
0 new messages