Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something fishy with lines() and looping over two items at a time in Rakudo #4623

Closed
p6rt opened this issue Oct 5, 2015 · 8 comments
Closed

Comments

@p6rt
Copy link

p6rt commented Oct 5, 2015

Migrated from rt.perl.org#126270 (status was 'resolved')

Searchable as RT126270$

@p6rt
Copy link
Author

p6rt commented Oct 5, 2015

From @masak

<Guest56815> p6​: spurt('/tmp/ABCD.txt', "A\nB\nC\nD"); for
'/tmp/ABCD.txt'.IO.lines() -> $x, $y { say "$x, then $y"; }
<camelia> rakudo-moar 0cca60​: OUTPUT«spurt is disallowed in restricted
setting [...]
<Guest56815> Okay. When running that code, I get "A, then B C, then D
Too few positionals passed; expected 2 arguments but got 0 [...]
<masak> Guest56815​: interesting. sounds like a bug. if there are 0
arguments then the loop should be over.
* masak tries to reproduce locally
<masak> yep, reproduced.
* masak submits rakudobug
<Guest56815> Thanks!
<masak> golfed​:
<masak> m​: for "A\nB\nC\nD".lines() -> $x, $y { say "$x, then $y" }
<camelia> rakudo-moar 0cca60​: OUTPUT«A, then B␤C, then D␤Too few
positionals passed; expected 2 arguments but got 0 [...]
<masak> no need for &spurt :)
<jnthn> m​: for |(1, 2), |(3, 4), |() -> $x, $y { say "$x, then $y" }
<camelia> rakudo-moar 0cca60​: OUTPUT«1, then 2␤3, then 4␤»
<jnthn> Hm, not that... :)
<masak> m​: for "A\nB\nC\nD".lines() -> $x { say $x }
<camelia> rakudo-moar 0cca60​: OUTPUT«A␤B␤C␤D␤»
<masak> m​: for [1,2,3,4] -> $x, $y { say "$x, then $y" }
<camelia> rakudo-moar 0cca60​: OUTPUT«1, then 2␤3, then 4␤»
<masak> ok, so something fishy with lines()
<jnthn> m​: my \i = "A\nB\nC\nD".lines.iterator; my @​x; (say
i.push-exactly(@​x, 2)) xx 3
<camelia> rakudo-moar 0cca60​: OUTPUT«2␤2␤0␤»
<jnthn> m​: my \i = <A B C D>.iterator; my @​x; (say i.push-exactly(@​x, 2)) xx 3
<camelia> rakudo-moar 0cca60​: OUTPUT«2␤2␤␤»
<jnthn> That's the discrepancy. The push-many in the lines iterator is
returning 0 when it should return IterationEnd
* masak adds that to the ticket

@p6rt
Copy link
Author

p6rt commented Oct 5, 2015

From @molecules

Attached are two examples that recreate the problem, one using "string.IO.lines()" and the other using "string.lines()".

(This is perl6 version 2015.09-234-gbd22d7e built on MoarVM version 2015.09-39-g1434283)

@p6rt
Copy link
Author

p6rt commented Oct 5, 2015

@p6rt
Copy link
Author

p6rt commented Oct 5, 2015

From @molecules

string_lines_error.p6

@p6rt
Copy link
Author

p6rt commented Oct 5, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 5, 2015

From @molecules

This earlier Perl6 version did NOT have this problem​:

perl6 version 2015.05-55-gd84bbbc built on MoarVM version 2015.05

Thanks!

@p6rt
Copy link
Author

p6rt commented Feb 9, 2016

From @AlexDaniel

This bug no longer exists in the latest versions of rakudo.

There is also a PR with a test​: Raku/roast#83

In other words, this ticket may be closed once the test is accepted.

@p6rt
Copy link
Author

p6rt commented Oct 4, 2017

@smls - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant