I have the following method in an action class that worked well in Rakudo 2016.07, but I just installed 2016.11 and now the new Rakudo says my method tries to assign to read-only varible, and I just don't see the problem:
method ptName ($/) {
my $nameStr = $/.Str, my $lastName, my $firstName;
my $newMatch # this is line 182;
# Cannot assign to a readonly variable or a value
= $nameStr.match(/ \" (<alpha>+) .*? \, \s* (<alpha>+) .*? \" /);
$lastName = $newMatch[0];
$firstName = $newMatch[1];
make "$lastName $firstName";
}
The whole error message is
Cannot assign to a readonly variable or a value
in method ptName at /home/lisprog/Binary/grammar.pl line 182
in regex ptName at /home/lisprog/Binary/grammar.pl line 151
in regex TOP at /home/lisprog/Binary/grammar.pl line 137
in block <unit> at /home/lisprog/Binary/grammar.pl line 217
What language spec has changed? Please help. Thanks.
=====================================================
Thank you raiph, Christoph, ZZ !! I don't know how to add a long comment with with right formatting. So, I am adding comments to my own post.
I wrote a test program, and now it seems that if I don't use ($/) in a method signature because I have to use .match inside the method, I can no long make anything. What did I do wrong? Here is the test program and the results:
The test program:
grammar test {
regex TOP { <foo><bar> }
regex foo { :i \s* foo \s* }
regex bar { :i \s bar \s* }
}
class actTest {
method foo ($x) { # program fails if I use $/ in signature
print "1 "; say $x; # how to combine the 2 and show $x as match?
print "2 "; say $x.WHAT;
my $newStr = $x.Str;
print "3 "; say $newStr;
my $newMatch
= $newStr.match(/:i(f)(oo)/); # adverb cannot be outside?
print "4 "; say $newMatch.WHAT;
print "5 "; say $newMatch;
print "6 "; say $/;
my $oo = $newMatch[1].Str;
print "10 "; say $oo;
my $f = $newMatch[0].Str;
print "11 "; say $f;
my $result = $oo ~ $f;
print "12 "; say $result;
make $result; # now I cannot make anything; huh???
}
method TOP ($/) {
print "8 "; say $<bar>;
print "9 "; say $<foo>.made; # failed, method 'foo' makes nothing
make $<bar> ~ $<foo>.made;
}
}
my $m = test.parse("Foo bar", actions => actTest.new);
print "7 "; say $m;
And the results:
1 「Foo 」
2 (Match)
3 Foo
4 (Match)
5 「Foo」
0 => 「F」
1 => 「oo」
6 「Foo」
0 => 「F」
1 => 「oo」
10 oo
11 F
12 ooF
1 「Foo」
2 (Match)
3 Foo
4 (Match)
5 「Foo」
0 => 「F」
1 => 「oo」
6 「Foo」
0 => 「F」
1 => 「oo」
10 oo
11 F
12 ooF
8 「 bar」
9 (Any)
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to
something meaningful.
in method TOP at matchTest.pl line 28
7 「Foo bar」
foo => 「Foo」
bar => 「 bar」
method ptName ($/ is copy) {
? What aboutmethod ptName ($/ is rw) {
? – Owl