如何使用将在已经定义的方法之前调用的多方法来扩充类?
我试图使负标:@arr[-1]在喜欢这个文章,但不改变源。
所以我用以下方法扩充Array:
augment class Array {
proto method AT-POS(Array:D: Int:D $i where <0 ) {
say "AT-POS called";
my $pos = -1;
my $ix = $pos + self.elems;
return self.AT-POS($ix);
}
};
Run Code Online (Sandbox Code Playgroud)
但正如文档中所述
Please note that adding a multi candidate that differs only
in its named parameters will add that candidate behind the already defined one
and as such it won't be picked by the dispatcher.
Run Code Online (Sandbox Code Playgroud)
所以我的 multi 永远不会被调用:
say .signature …Run Code Online (Sandbox Code Playgroud) FAQ:在 Raku 中,如何从列表中删除重复项以仅获取唯一值?
my $arr = [1, 2, 3, 2, 3, 1, 1, 0];
# desired output [1, 2, 3, 0]
Run Code Online (Sandbox Code Playgroud) FAQ:在 Raku 中,如何将字符串转换为其十六进制的字节列表(即十六进制解码器)
目前,我有:
say "I ? ".encode.list.map(*.base(16)); # (49 20 E2 9D A4 20 F0 9F A6 8B)
Run Code Online (Sandbox Code Playgroud)
这是4个操作
常见问题解答:在 Raku 中,如何解析String并获得Number?例如:
xxx("42"); # 42 (Int)
xxx("0x42"); # 66 (Int)
xxx("42.123456789123456789"); # 42.123456789123456789 (Rat)
xxx("42.4e2"); # 4240 (Rat)
xxx("42.4e-2"); # 0.424 (Rat)
Run Code Online (Sandbox Code Playgroud)