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

s/// in &map doesn't change the elements in Rakudo #3050

Closed
p6rt opened this issue Feb 12, 2013 · 3 comments
Closed

s/// in &map doesn't change the elements in Rakudo #3050

p6rt opened this issue Feb 12, 2013 · 3 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Feb 12, 2013

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

Searchable as RT116731$

@p6rt
Copy link
Author

p6rt commented Feb 12, 2013

From @masak

<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.

@p6rt
Copy link
Author

p6rt commented Jul 18, 2015

From @perlpilot

Fixed in rakudo/rakudo@48c0ba5

Test added in Raku/roast@a8a86ef

--
perlpilot

@p6rt p6rt closed this as completed Jul 18, 2015
@p6rt
Copy link
Author

p6rt commented Jul 18, 2015

@perlpilot - Status changed from 'new' to 'resolved'

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant