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

Array mutation sometimes ignored within a loop #1898

Open
mscha opened this issue Jun 3, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@mscha
Copy link

commented Jun 3, 2018

The Problem

Perl 6 lets you do awesome stuff like

my @r = 2,4,6;
my $div = @r[0];
@r X/= $div;
dd @r;   # output: Array @r = [1.0, 2.0, 3.0]

However, when I try to do this in a loop in a matrix (array of arrays):

my @m = [1,2,3],[2,6,10],[3,12,21];
for @m -> @r {
    my $div = @r[0];
    @r X/= $div;
}
dd @m;   # output: Array @m = [[1, 2, 3], [2, 6, 10], [3, 12, 21]]

If you add a dummy statement after the X/=. it starts working correctly:

my @m = [1,2,3],[2,6,10],[3,12,21];
for @m ->@r {
    my $div = @r[0];
    @r X/= $div;
    $div += 0;
}
dd @m;   # output: Array @m = [[1.0, 2.0, 3.0], [1.0, 3.0, 5.0], [1.0, 4.0, 7.0]]

Expected Behavior

It works even if the X/= is the last statement in the loop

Actual Behavior

It only works correctly if the X/= is not the last statement in the loop

Steps to Reproduce

See above.

Environment

  • Operating system: Ubuntu 18.04 LTS via WSL on Windows 10
  • Compiler version (perl6 -v): This is Rakudo Star version 2018.04.1 built on MoarVM version 2018.04.1 implementing Perl 6.c.

(But behaves the same using the latest rakudo in IRC as of 3 June 2018; rakudo-moar 398c270.)

See also

https://irclog.perlgeek.de/perl6/2018-06-03#i_16239480

@mscha

This comment has been minimized.

Copy link
Author

commented Jun 3, 2018

Note that this problem seems to be specific to the cross meta-operator (X). The following code does work as expected:

my @m = [1,2,3],[2,6,10],[3,12,21];
for @m -> @r {
    my $div = @r[0];
    @r[1] /= $div;
}
dd @m;   # output: Array @m = [[1, 2.0, 3], [2, 3.0, 10], [3, 4.0, 21]]
@zoffixznet

This comment has been minimized.

Copy link
Contributor

commented Jun 3, 2018

Sounds like another case of issues due to our current sinker code #1571

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.