本机属性可以用作参数中的绑定目标吗?
Can native attributes be used as bind target in parameters?
根据6.d (current version) check list,他们可以。
然而,
class Foo {
has num $.numillo;
submethod BUILD( :$numillo = 3.5 ) {}
};
my $foo = Foo.new;
say $foo.raku; # OUTPUT: «Foo.new(numillo => 0e0)»
该属性似乎不可绑定,或者至少没有分配值。我在这里遗漏了什么吗?
您只是为 BUILD
中的命名参数赋值,而非 属性!
submethod BUILD( :$!numillo = 3.5e0 ) {}
应该解决这个问题(注意签名中的 !)。另请注意 3.5
不是 而不是 和 num
,您必须通过添加 e0
.
使其成为一个
根据6.d (current version) check list,他们可以。
然而,
class Foo {
has num $.numillo;
submethod BUILD( :$numillo = 3.5 ) {}
};
my $foo = Foo.new;
say $foo.raku; # OUTPUT: «Foo.new(numillo => 0e0)»
该属性似乎不可绑定,或者至少没有分配值。我在这里遗漏了什么吗?
您只是为 BUILD
中的命名参数赋值,而非 属性!
submethod BUILD( :$!numillo = 3.5e0 ) {}
应该解决这个问题(注意签名中的 !)。另请注意 3.5
不是 而不是 和 num
,您必须通过添加 e0
.