clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
2020-12-09T09:50:27.287900Z

Is it a bug?

(partition 3 1 [:a :b :c] (range 5))
; => ((0 1 2) (1 2 3) (2 3 4) (3 4 :a))
I would expect ((0 1 2) (1 2 3) (2 3 4)) as a result instead.

2020-12-09T09:55:34.288700Z

Isn’t it working exactly as described in docstring?

2020-12-09T10:12:01.289700Z

The docstring is ambiguous on this point.

2020-12-09T10:14:30.290400Z

as a comparison with partition-all, there is an inconsistency.

(partition-all 3 1 (range 5))
=> ((0 1 2) (1 2 3) (2 3 4) (3 4) (4))

2020-12-09T10:18:32.291500Z

if partition was behaving consistently with partition-all, it should be:

(partition 3 1 [:a :b :c] (range 5))
; => ((0 1 2) (1 2 3) (2 3 4) (3 4 :a) (4 :a :b))

2020-12-09T10:42:54.293500Z

hm… but docstring for partition is not mentioning partition-all however I can see some problems with that sentence:

If a pad collection is supplied, use its elements as
necessary to complete last partition upto n items.
there is no definition what is last partition

2020-12-09T10:57:39.294100Z

there should be an emphasis on the "last partition" with no s

2020-12-09T10:58:54.295300Z

But yeah ... the last partition is not defined.

2020-12-09T10:59:22.296200Z

of it could be first incomplete partition

2020-12-09T11:00:57.296900Z

(partition 3 3 [:a :b :c] (range 9))
=> ((0 1 2) (3 4 5) (6 7 8))
Your formulation does not apply.

2020-12-09T11:01:35.297200Z

I think that it is a bug.

2020-12-09T11:02:58.297800Z

what do you expect?

2020-12-09T11:05:07.299500Z

I would expect the "last partition" to be: > > The last partition to contain elements from the input collection (not the padding collection) which are not present in any previous partition.

2020-12-09T11:05:50.300300Z

but this (6 7 8) is that partition, isn’t it?

2020-12-09T11:05:52.300400Z

It would mean:

(partition 3 3 [:a :b :c] (range 10))
; => ((0 1 2) (3 4 5) (6 7 8) (9 :a :b)) ; actual behavior

(partition 3 3 [:a :b :c] (range 9))
; => ((0 1 2) (3 4 5) (6 7 8)) ; actual behavior

(partition 3 1 [:a :b :c] (range 5)) ; suspected bug here
; => ((0 1 2) (1 2 3) (2 3 4) (3 4 :a)) ; actual behavior
; => ((0 1 2) (1 2 3) (2 3 4)) ; not actual behavior, but that's what I expect.

2020-12-09T11:14:02.301700Z

Does it make sense to you?

2020-12-09T11:29:40.307400Z

(partition 3 1 [:a :b :c] (range 5))
;; ((0 1 2) (1 2 3) (2 3 4) (3 4) (3))
;;  ^_____________________^ ^_______^
;;  complete partitions     those are incomplete
;;  each of size 3          size != 3
;;  each at offset apart    each at offset apart
two last partitions partition should drop because it against first part of the docstring but we supply third argument (pad) so we should read carefully second part. If a pad collection is supplied, use its elements as necessary to complete last partition upto n items. so we must complete last partition using elements in pad to do that we need to define last partition and because there is no definition in the docstring we have to guess If you consider my suggestion: first incomplete partition will be (3 4) then this “incomplete partition” should be completed using element from pad list. as a result: (3 4 :a) so this is correct behavior for me as I understand docstring for partition function

2020-12-09T11:32:29.309100Z

but also my english skills are not sharp enough to suggest the wording for clojure.core )

2020-12-09T11:32:58.309500Z

I just tried to give my personal understanding of the function

2020-12-09T11:53:49.311100Z

I see ... but in practice, it is useless to return (3 4 :a) because 3 and 4 were already returned in the previous partition. So IMHO, it is still fishy/buggy.

2020-12-09T12:06:40.314300Z

this is still useful in case nil-padding is not desired (which makes usage of partition-all useless) something like (partition 3 1 (repeat 2 :n-a) '(1 nil 3 nil 4 nil 5 nil 6 nil)) here I want to clear the difference between nil value coming from my list and an indicator of absence of value because “not enough elements to fill the partition”

favila 2020-12-09T12:12:45.317300Z

I would want and expect current behavior. It seems fishy because the partitions are overlapping and you are thinking of items not “windows”. I rely on this behavior to give me a sliding window over a seq that fills in the tail.

2020-12-09T12:16:32.319400Z

@favila are you using different values for n and step ? I want to make sure that we are talking about the same thing.

favila 2020-12-09T12:17:30.320500Z

So in your example, every element that would be collected by “step” defines a partition

favila 2020-12-09T12:18:12.321600Z

If there are less than n items left after it, it is normally dropped, unless enough pad is supplied

favila 2020-12-09T12:18:58.321800Z

> I see ... but in practice, it is useless to return (3 4 :a) because 3 and 4 were already returned in the previous partition. So IMHO, it is still fishy/buggy.

favila 2020-12-09T12:20:01.322800Z

I’m saying no, because 3 was not in the first position of the previous partition

2020-12-09T12:21:49.325200Z

If the function was following this logic, there should be another partition (4 :a :b) after that

favila 2020-12-09T12:21:50.325300Z

I actually expect an additional (4 :b :c), I’m not sure why there isn’t one

favila 2020-12-09T12:22:23.325800Z

I guess the logic is you will only get one incomplete partition

favila 2020-12-09T12:22:49.326600Z

And yeah, that breaks how I use partition for windowing if n>2

2020-12-09T12:24:00.327Z

So we agree that there is a problem, there?

favila 2020-12-09T12:24:30.327700Z

Yeah but we have opposite conceptions of what is the correct behavior :)

favila 2020-12-09T12:27:04.330200Z

i don’t think current behavior violates the doc though. I just would like it to go further

favila 2020-12-09T12:27:42.331200Z

But definitely the “step” not “n” defines the partitions, not whether an item was consumed

alexmiller 2020-12-09T14:33:03.332Z

Please file a problem on http://ask.clojure.org