我正在尝试使用Enumeration
role in Perl 6的示例(作为解决文档问题Enumeration role is not documented的一部分)。我想出了一个简单的例子:
text = "I am happy with <body> <h1>This is a Heading</h1> <p>This is a paragraph.</p> </body> 3333 <body> <h1>This is a Heading</h1> <p>This is a paragraph.</p> </body> your code"
print(remove_tags(text))
>
I am happy with 3333 your code
text = "x<=1 <div> cookies </div>"
print(remove_tags(text))
>
x<=1
text = "I am <a happy with <body> </body> lal"
print(remove_tags(text))
>
I am <a happy with lal
理论上,class DNA does Enumeration {
my $DNAindex = 0;
my %pairings = %( A => "T",
T => "A",
C => "G",
G => "T" );
method new( $base-pair where "A" | "C" | "G" | "T" ) {
self.bless( key => $base-pair,
value => %pairings{$base-pair},
index => 33);
}
multi method gist(::?CLASS:D:) {
return "$!key -> $!value with $!index";
}
}
for <A C G T>.roll( 16 ) -> $letter {
my DNA $base = DNA.new( $letter );
say "Pairs ", $base.pair, " with ", $base.gist;
}
Enumeration
has
,并且我尝试使用$!index
为其分配一个值;但是,它返回的只是类似
index => 33
任何其他直接为$!index赋值的方法,我得到the "cannot assign to an immutable value,我遇到了另一个问题。根据{{3}},这可能是一个错误;在这种情况下,我想知道是否有解决方法。
答案 0 :(得分:3)
这是一个错误Cannot change native role attribute from consuming class(与您链接的答案中提到的错误无关)。
我不知道解决方法。