Help!
FeepingCreature
feepingcreature at gmail.com
Fri Jun 16 08:41:48 UTC 2023
On Thursday, 15 June 2023 at 19:18:03 UTC, H. S. Teoh wrote:
> https://issues.dlang.org/show_bug.cgi?id=23976
>
> Caused by: https://github.com/dlang/phobos/pull/8738
> (commit 8a9cfa2677)
>
> Brief summary:
>
> ```
> import std;
> void main() {
> auto input = "1<2";
> foreach (pair; input.splitter("<").slide(2))
> {
> writeln(pair);
> }
> }
> ```
>
> Output before commit 8a9cfa2677:
> ```
> ["1", "2"]
> ```
>
> Output after commit 8a9cfa2677:
> ```
> ["1", "2"]
> ["2"]
> ```
>
> This is incorrect because the code asked for a window of size
> 2, with the default option of No.withPartial.
>
> This broke another of my old projects that relied on the old
> (correct)
> behaviour. :-/
>
>
> T
I actually need some help with this.
The behavior of `withPartial` seems to be random! For instance,
since the default of `slide` is stated to be `Yes.withPartial`,
shouldn't `[["1", "2"], ["2"]]` be the correct answer, since the
last element has less than two entries?
But then the unittests on
https://dlang.org/library/std/range/slide.html are all over the
place. For instance:
```
assert([0, 1, 2, 3].slide(2).equal!equal(
[[0, 1], [1, 2], [2, 3]]
));
```
But this is `Yes.withPartial` too! So shouldn't it end with `,
[3]`?
Either I'm severely not getting something here, or the bug report
is in fact the wrong way around and the bug is that `slide`
sometimes *doesn't* append the partial last window.
Do we just need to revert my PR, throw up our hands and admit
that the behavior of `slide` is just basically down to the
vagaries of range semantics, and start over with `slide2`?
More information about the Digitalmars-d
mailing list