I nursed this one to know where the problem is, but unsure of the fix. Maybe someone can figure out how to push it through the finish line...
First, the problem shown in the OP is weird only because there's a level of indirection with the iterator and the problem there shows up only after we attempt to fetch already reified items. Here's a simpler reproduction with both S/// and s///: <ZoffixW> m: say do for <a1 a2 a3 a4> { S/a/z/; } <camelia> rakudo-moar 9a3c35: OUTPUT«(z4 z4 z4 z4)» <ZoffixW> m: say do for <a1 a2 a3 a4> -> $_ is copy { s/a./z/; } <camelia> rakudo-moar 9a3c35: OUTPUT«(「a4」 「a4」 「a4」 「a4」)» The problem is the `S///` and `s///` ops use the $/ and return it. This value becomes an item in the loop's result list, but the next loop iteration updates the $/, so all the previous items in the list get updated to it as well, which is why we see all items in the output set to the last item. I looked through some past commits mentioning $/ for ideas, and tried the following, but that didn't fix anything... I'm out of ideas now. cpan@perlbuild2~/CPANPRC/rakudo (nom)$ gd diff --git a/src/Perl6/Actions.nqp b/src/Perl6/Actions.nqp index 0a4acb3..5a3f3b1 100644 --- a/src/Perl6/Actions.nqp +++ b/src/Perl6/Actions.nqp @@ -7781,6 +7781,13 @@ class Perl6::Actions is HLL::Actions does STDActions { $past := QAST::Op.new( :op('locallifetime'), :node($/), QAST::Stmt.new( + QAST::Op.new( :op('bind'), + QAST::Var.new( :name('$/'), :scope('lexical') ), + QAST::Op.new( + :op('getlexdyn'), + QAST::SVal.new( :value('$/') ), + ) + ), # my $result; QAST::Var.new( :name($result), :scope('local'), :decl('var') ), cpan@perlbuild2~/CPANPRC/rakudo (nom)$ Cheers, ZZ On Thu, 15 Dec 2016 09:47:06 -0800, bdug...@matatu.org wrote: > This code: > > say <a1 a2 a3>.map({S/a/x/}).perl > > returns this: > > ("x3", "x3", "x3").Seq > > instead of x1, x2, x3. > > Version: 2016.11 > > IRC snippet below. > > [12:27] == bdmatatu [6c347aa0@gateway/web/freenode/ip.108.52.122.160] > has joined #perl6 > [12:30] <bdmatatu> p6: say <a1 a2 a3>.map({S/a/x/}).perl > [12:30] <+camelia> rakudo-moar 9a3c35: OUTPUT«("x3", "x3", "x3").Seq» > [12:30] == dakkar [~dakkar@2001:8b0:6448:5fae:b18a:bf2:877d:4f6d] has > quit [Ping timeout: 245 seconds] > [12:30] <bdmatatu> I was expecting x1 x2 x3 > [12:35] <AlexDaniel> bdmatatu: interesting… looks like there's > something wrong with .perl? > [12:35] <AlexDaniel> bisect: say <a1 a2 a3>.map({S/a/x/}).perl > [12:36] <+bisectable6> AlexDaniel, On both starting points > (old=2015.12 new=9a3c350) the exit code is 0 and the output is > identical as well > [12:36] <+bisectable6> AlexDaniel, Output on both points: ("x3", "x3", > "x3").Seq > [12:36] <AlexDaniel> commit: all say <a1 a2 a3>.map({S/a/x/}).perl > [12:36] <+committable6> AlexDaniel, > https://gist.github.com/e5004d10ec77d2addd00e40d6f1a6771 > [12:37] == donaldh [chatzilla@nat/cisco/x-adftzffgeuuokccx] has quit > [Remote host closed the connection] > [12:39] <bdmatatu> p6: say <a1 a2 a3>.map({ S/a/x/ })[0] > [12:39] <+camelia> rakudo-moar 9a3c35: OUTPUT«x1» > [12:39] <bdmatatu> p6: say <a1 a2 a3>.map({ S/a/x/ }).eager[0] > [12:39] <+camelia> rakudo-moar 9a3c35: OUTPUT«x3» > [12:40] <AlexDaniel> m: say <a1 a2 a3>.map({S/huh//}) > [12:40] <+camelia> rakudo-moar 9a3c35: OUTPUT«(a1 a2 a3)» > [12:40] <AlexDaniel> m: say eager <a1 a2 a3>.map({S/huh//}) > [12:40] <+camelia> rakudo-moar 9a3c35: OUTPUT«(a3 a3 a3)» > [12:41] <AlexDaniel> huggable: bug report > [12:41] <huggable> AlexDaniel, nothing found > [12:41] <AlexDaniel> huggable: bug > [12:41] <huggable> AlexDaniel, nothing found > [12:41] <AlexDaniel> huggable: report bug > [12:41] <huggable> AlexDaniel, nothing found > [12:41] <AlexDaniel> meh > [12:41] <AlexDaniel> bdmatatu: anyway, this looks like a bug, can you > submit a ticket? > [12:41] <bdmatatu> Okay, sure, thanks