Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

Dorun can be called as (dorun n coll). When called this way, dorun will force n+1 elements from coll, which seems unintuitive. I can't necessarily call this a defect, though. It doesn't deviate from the documented behavior because there is no documented behavior -- the two-argument arity is not mentioned in the docstring.

`
user=> (defn printing-range [n] (lazy-seq (println n) (cons n (printing-range (inc n)))))

'user/printing-range

user=> (dorun 0 (printing-range 1))
1
nil
user=> (dorun 3 (printing-range 1))
1
2
3
4
nil
`

2 Answers

0 votes
by

Comment made by: stu

I do not think this is a bug, as it is caused by the pervasive semantics of {{seq}}, not just of {{dorun}}. Consider

(def x (seq (printing-range 0))) 0

i.e. just calling {{seq}} consumes the first item. I am leaving open as a feature request for improved docstring.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1655 (reported by michaelblume)
...