You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<uvtc> r: my @a = <foo bar baz>; map( { s/a/A/ }, @a ); say @a;
<p6eval> rakudo a3869a: OUTPUT«foo bar baz»
<uvtc> Hm. Was expecting foo bAr bAz there.
<uvtc> In Perl 5, if I put an s/// inside a `map`, it modifies the
items in the array. Does Perl 6 behave the same way?
<moritz> n: my @a = <foo bar baz>; map( { s/a/A/ }, @a ); say @a;
<p6eval> niecza v24-23-g0520c7c: OUTPUT«foo bAr bAz»
<moritz> uvtc: I think it's a bug in rakudo
* masak submits rakudobug
<moritz> somwhere the rw-ness of $_ gets lost
<uvtc> Thanks!
<colomon> huh, I would have thought that was a nieczabug
<uvtc> Why does s/// inside the `map` change the original array? Is it
because that's what most commonly wanted in that situation?
<masak> it's because $_ is bound rw.
<masak> as in <-> $_ { ... }
<uvtc> It would seem to me that if I want to change the array, I'd use
a `for` loop. Whereas, `map` would be used exclusively for creating
new arrays.
<moritz> uvtc: map and for loops are really the same in Perl 6
<uvtc> Ah. Ok. Thanks.
Migrated from rt.perl.org#116731 (status was 'resolved')
Searchable as RT116731$
The text was updated successfully, but these errors were encountered: