我正在玩这个小东西,其中一组可以通过翻转测试来充当它的补充.为了实现这一目标,我创建了会员运营商的特殊版本.
class Complement {
has $.set;
}
multi infix:<?> ( $a, Complement:D $c ) { $a ? $c.set }
multi infix:<?> ( $a, Complement:D $c ) { $a ? $c.set }
my $set = (1, 2, 3).Set;
my $c = Complement.new: set => $set;
put 3 ? $set;
put 4 ? $c;
Run Code Online (Sandbox Code Playgroud)
根据我infix:<?>对另一个的定义,更普遍的似乎已经消失了.没有其他候选人:
True
Cannot resolve caller infix:<?>(Int, Set); none of these signatures match:
($a, Complement:D $c)
in sub infix:<?> at /Users/brian/Desktop/complement.p6 line 11
in block <unit> at …Run Code Online (Sandbox Code Playgroud) 我有一个用perl6的子集命令构造的类型层次结构,以及一些专门针对这些类型的多子类.当多调度发生时,如何通过最窄的子类型赋予最高优先级?
这是简化的代码:
#! /usr/bin/env perl6
use v6.c;
proto check($value) { * }
subset Positive of Int where * > 0;
subset PositiveEven of Positive where * %% 2;
multi check(Int $value) {
say "integer"
}
multi check(Positive $value) {
say "positive"
}
multi check(PositiveEven $value) {
say "positive & even"
}
# example:
check(32);
# expected output:
# positive & even
# actual output:
# positive
Run Code Online (Sandbox Code Playgroud) 考虑一下我在参数列表中构造一个Array的程序.虽然有一个接受数组的签名,但这会调用接受List的签名:
foo( [ 1, 2, 3 ] );
multi foo ( Array @array ) { put "Called Array @ version" }
multi foo ( Array $array ) { put "Called Array \$ version" }
multi foo ( List $list ) { put "Called List version" }
multi foo ( Range $range ) { put "Called Range version" }
Run Code Online (Sandbox Code Playgroud)
我得到了意外例程的输出:
Called Array $ version
Run Code Online (Sandbox Code Playgroud)
如果我取消注释其他签名,则会调用该签名:
Called List version
Run Code Online (Sandbox Code Playgroud)
为什么不称它为( Array @array )版本?调度员如何做出决定(以及记录在哪里)?