gpt4 book ai didi

mixins - 为混合角色的属性赋值

转载 作者:行者123 更新时间:2023-12-04 12:39:11 25 4
gpt4 key购买 nike

我正在尝试使用 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 has $!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 (与您链接的答案中提到的无关)。

我不知道有什么解决方法。

关于mixins - 为混合角色的属性赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51632394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com