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

0 votes
in Docs by

The range function's documentation does indicate the following usage:

(range 10 0 -1) -> (10, 9, 8, 7, 6, 5, 4, 3, 2, 1)

Current doc:

Returns a lazy seq of nums from start (inclusive) to end (exclusive), by step, where start defaults to 0, step to 1, and end to infinity. When step is equal to 0, returns an infinite sequence of start. When start is equal to end, returns empty list.

Its also possible to step down rather than up, for example counting
backwards from 10 by -1: (range 10 0 -1).

Proposed:

Add final sentence: "Step may be negative."

Patch: clj-704.patch

8 Answers

0 votes
by

Comment made by: raek

The current doc actually mentions the 'step' parameter briefly:

"(link: ...) to end (exclusive), by step, where start (link: ...)"

But as this might be easy to miss, an addition to the doc is still a good idea, I think.

My suggestion:

Returns a lazy seq of nums from start (inclusive) to end
(exclusive), by step, where start defaults to 0, step to 1, and end
to infinity. Step may be negative to count backwards.

0 votes
by

Comment made by: pbalduino

There was any news about it?

Could I assign it to me?

0 votes
by

Comment made by: jafingerhut

No, no news about this one. It is in the 'open' state, meaning that there is currently no judgement as to whether Clojure screeners or Rich Hickey are interested in such a change. http://dev.clojure.org/display/community/JIRA workflow

That said, it seems like it should not take a lot of time to create a patch. Detailed instructions are given here: http://dev.clojure.org/display/community/Developing Patches

0 votes
by

Comment made by: alexmiller

Go for it!

0 votes
by

Comment made by: pbalduino

I cannot reproduce this: "When step is equal to 0, returns an infinite sequence of start."

https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L2726-L2729

Is this correct?

0 votes
by

Comment made by: jafingerhut

The last time range was modified was due to ticket CLJ-1018. See the attached patch there, which I believe is the one that was applied after Clojure 1.5 but before Clojure 1.6.

Perhaps that change does not do what it claimed to do in the doc string. I haven't looked at it in detail yet.

0 votes
by

Comment made by: jafingerhut

In Clojure 1.6, it appears that it may be more accurate if the last two sentences in the doc string were modified. range's doc string is currently:

Returns a lazy seq of nums from start (inclusive) to end
(exclusive), by step, where start defaults to 0, step to 1, and end to
infinity. When step is equal to 0, returns an infinite sequence of
start. When start is equal to end, returns empty list.

It might be more accurate to say:

Returns a lazy seq of nums from start (inclusive) to end
(exclusive), by step, where start defaults to 0, step to 1, and end to
infinity. When start is equal to end, returns empty list. When step
is equal to 0 and start and end differ, returns an infinite sequence of
start.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-704 (reported by alex+import)
...