我有在Rakudo 2016.07行之有效的动作类下面的方法,但我刚安装了2016.11现在新Rakudo说我的方法试图将分配给只读varible,我只是不明白的问题:perl6 rakudo 2016.11匹配尝试分配给只读变量,为什么不在2016.07?
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";
}
整个错误消息是
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
什么语言规范变化?请帮忙。谢谢。
============================================== =======
谢谢raiph,克里斯托夫,ZZ!我不知道如何用正确的格式添加长评论。所以,我正在给自己的帖子添加评论。
我写了一个测试程序,现在看来,如果我没有在方法签名使用(/ $),因为我必须使用.match的方法中,我不能长期做任何事情。我做错了什么?下面是测试程序和结果:
测试程序:
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;
而结果:
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){'?那么'方法ptName($ /是rw){'? – raiph
谢谢你raiph!当我在任何$ a = $ someString.match()上使用($/is copy)时,程序运行,但是没有给出有意义的$ a [0]或$ a [1];当我使用($ /是rw)时,发生新的错误,并且它说“参数'$ /'预期可写容器,但获得了匹配值”。我在Rakudo 2016.07中没有这个问题。我认为2016.11有些事情会爆发。上次我试图报告错误时,邮件以无法投递的方式反弹回来。谢谢。 – lisprogtor
@lisprogtor:人们似乎能够再次打开门票,参见http://perl6.fail/ – Christoph