mixins – 为混合角色的属性赋值
发布时间:2020-12-15 23:37:06 所属栏目:大数据 来源:网络整理
导读:我正在尝试使用 Enumeration role in Perl 6(作为修复文档问题 Enumeration role is not documented的一部分)的示例.我想出了这个简单的例子: class DNA does Enumeration { my $DNAindex = 0; my %pairings = %( A = "T",T = "A",C = "G",G = "T" ); metho
我正在尝试使用
Enumeration role in Perl 6(作为修复文档问题
Enumeration role is not documented的一部分)的示例.我想出了这个简单的例子:
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有$!index,而index => 33我试着给它分配一个值;然而,它返回的就像是 Pairs T => A with T -> A with 0 任何其他方式直接为$!index分配一个值,我得到the “cannot assign to an immutable value我得到了另一个问题.根据one of the answers,这可能是一个错误;在这种情况下,我想知道是否有一些解决方法. 解决方法
这是一个错误
Cannot change native role attribute from consuming class(与您链接的答案中提到的错误无关).
我不知道一个解决方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |