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
roundrobin doesn't work as expected on arrays #5955
Comments
From @mscha my @l = (0,1,2),(3,4,5),(6,7); outputs (((0 1 2) (3 4 5) (6 7))) instead of the expected ((0 3 6) (1 4 7) (2 5)) The following *does* work: my $l = ((1,2,3),(4,5,6),(7,8)); Note that zip (the function) has the same issue, but Z (the operator) my @l = (0,1,2),(3,4,5),(6,7); outputs: (((0 1 2) (3 4 5) (6 7))) Unfortunately, there is no operator for roundrobin (right?) that I can Latest Rakudo Star: This is Rakudo version 2016.11 built on MoarVM version 2016.11 |
From @zoffixznetOn IRC I said this was a bug, because the behaviour seemed so surprising, but now that I made a fix for it (diff attached), I find breakage in t/spec/S03-metaops/zip.t and t/spec/S32-container/roundrobin.t that test for what I see is a contradictory (to this ticket) behaviour for RT#126522. Basically roundrobin, zip, and a few others aren't meant to treat itemized lists as lists and instead treat them as a single item. This is why the behaviour in this ticket is observed: array's elements are itemized and so get treated differently. So.... this is just a pitfall of sorts and isn't a bug? |
From @zoffixznetdiff.diffdiff --git a/src/core/List.pm b/src/core/List.pm
index 4edd254..172009b 100644
--- a/src/core/List.pm
+++ b/src/core/List.pm
@@ -1593,14 +1593,14 @@ multi sub infix:<Z>(+lol) {
return Seq.new(Rakudo::Internals.EmptyIterator) if $arity == 0;
eager my @l = (^$arity).map: -> $i {
my \elem = lol[$i];
- if nqp::iscont(elem) {
- $laze = False;
- Rakudo::Internals.WhateverIterator((elem,))
- }
- else {
+ if nqp::istype(elem, Iterable) {
$laze = False unless elem.is-lazy;
Rakudo::Internals.WhateverIterator(elem)
}
+ else {
+ $laze = False;
+ Rakudo::Internals.WhateverIterator((elem,))
+ }
}
gather {
@@ -1622,13 +1622,13 @@ my &zip := &infix:<Z>;
sub roundrobin(**@lol is raw) {
my $laze = False;
my @iters = do for @lol -> \elem {
- if nqp::iscont(elem) {
- (elem,).iterator
- }
- else {
+ if nqp::istype(elem, Iterable) {
$laze = True if elem.is-lazy;
elem.iterator
}
+ else {
+ (elem,).iterator
+ }
}
gather {
while @iters {
|
The RT System itself - Status changed from 'new' to 'open' |
From @zoffixznetper jnthn++ https://irclog.perlgeek.de/perl6-dev/2017-01-04#i_13854591 Turns out this is not a bug, but a consequence of arrays itemizing their contents. You can still use the array, but you need to ».list on it it to de-itemize the contents; same with `zip`: <ZoffixW> m: my @l = (0,1,2),(3,4,5),(6,7); say zip @l».list.Slip; |
@zoffixznet - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#130498 (status was 'resolved')
Searchable as RT130498$
The text was updated successfully, but these errors were encountered: