运行在莫尔(2016.10)
考虑构建一个集合并测试成员资格的代码:
my $num_set = set( < 1 2 3 4 > ); say "set: ",$num_set.perl; say "4 is in set: ",4 ∈ $num_set; say "IntStr 4 is in set: ",IntStr.new(4,"Four") ∈ $num_set; say "IntStr(4,...) is 4: ","Four") == 4; say "5 is in set: ",5 ∈ $num_set;
一个直4不在集合,但IntStr版本是:
set: set(IntStr.new(4,"4"),IntStr.new(1,"1"),IntStr.new(2,"2"),IntStr.new(3,"3")) 4 is in set: False IntStr 4 is in set: True IntStr(4,...) is 4: True 5 is in set: False
我认为大多数人都不会期待这一点,但是∈docs并没有说明这个方法是如何工作的.如果我不使用报价单(即设置(1,2,3,4)),我没有这个问题.