Clojure

(partition 0 seq) and (parition-all 0 seq) are infinite sequences of empty sequences

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.1, Release 1.2
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

(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.

Activity

Hide
Paul Stadig added a comment -

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

Show
Paul Stadig added a comment - Ugh! I didn't mean for this to be major priority, and I can't seem to edit it after the fact.
Andy Fingerhut made changes -
Field Original Value New Value
Priority Major [ 3 ] Minor [ 4 ]
Hide
Mike Anderson added a comment -

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.

Show
Mike Anderson added a comment - 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.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated: