On Mon Sep 17 09:34:45 2012, nicholas wrote: > Well, I don't think that I'm doing anything stupid here, but it's > always > a possibility. > > Surely if function parameters are readonly *aliases* to the argument > passed to the function, then they should see modifications made to > that > argument by other parts of the code. eg > > $ cat ../test/aliases.pl > use v6; > > my $global = "Perl Rules"; > > sub baz { > $global ~~ s/Perl /Perl 6/; > } > > sub foo ($bar) { > say $bar; > baz; > say $bar; > try { > ++$bar; > } > say $!; > } > > foo($global); > > say "But at the end: $global"; > $ ./perl6 ../test/aliases.pl > Perl Rules > Perl Rules > Cannot assign to a readonly variable or a value > in sub prefix:<++> at src/gen/CORE.setting:1350 > in sub foo at ../test/aliases.pl:14 > in block at ../test/aliases.pl:19 > > But at the end: Perl 6 Rules > > > I would have expected the second line to be "Perl 6 Rules", because > the > aliased value has been changed by the call to &baz(). > > $ ./perl6 -v > This is perl6 version 2012.07-270-g5e1b9a8 built on parrot 4.4.0 > revision RELEASE_4_4_0 > > > Yes, there is an ulterior motive to this bug report. I'm not confident > that > read only aliases are actually an optimiser win. You mustn't assume > that the > aliased value remains unchanged by any opaque action, such as a > function > call, else you break correctness. > Indeed, and we didn't implement it as readonly aliases, and if we did go with that behavior then it would enormously hinder things like spesh and invokedynamic in their optimization work. So, now the design docs are in line with what's actually been implemented:
https://github.com/perl6/specs/commit/1903a509e3