<< Back to previous view

[CLJ-764] (partition 0 seq) and (parition-all 0 seq) are infinite sequences of empty sequences Created: 21/Mar/11  Updated: 11/Apr/15  Resolved: 11/Apr/15

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.1, Release 1.2
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Paul Stadig Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None


(partition n seq) and (partition-all n seq) are implemented by taking n and dropping n from seq. When n=0 this becomes an infinite sequence of empty sequences.

While conceptionally this makes sense, I think practically it may surprise people, and perhaps it should return an empty sequence or a sequence of a single empty sequence.

Comment by Paul Stadig [ 21/Mar/11 9:22 AM ]

Ugh! I didn't mean for this to be major priority, and I can't seem to edit it after the fact.

Comment by Mike Anderson [ 21/Jan/13 5:40 AM ]

I think the current behaviour is logically more correct than returning a empty sequence or a single empty sequence.

In particular, I would expect (partition n infinite-seq) to return an infinite sequence of sequences of length n, for any value of n >= 0. Anything else would be very surprising.

The only other sensible option would be throwing an exception, on the philosophical grounds that it isn't possible to partition a non-empty sequence into sub-sequences of length 0. But I think that changing behaviour in this way would break backwards compatibility for no obvious gain.

I suggest closing this issue.

Comment by Andrea Richiardi [ 11/Apr/15 10:12 AM ]

I am checking the partition function as well as I making, using recur, tail-recursive.
I have run into this issue while testing. Then I came here and spotted it.
At least I would suggest to remove these from ...test_clojure/sequences.clj:
{{(partition -1 [1 2 3]) ()}}
{{(partition -2 [1 2 3]) ()}}

I will do it as soon as I have finished my little change..

Comment by Alex Miller [ 11/Apr/15 10:20 AM ]

No plans to change this.

Generated at Thu Jan 18 08:26:28 CST 2018 using JIRA 4.4#649-r158309.