cod*_*ons 6 set rakudo semantics raku
应该&set, Set, 和Set.new有不同的语义吗?如果是这样,为什么?
考虑以下代码:
\nmy @array = 1, 2;\nmy @other-array = ([3, 4],);\n\ndd set(@array, @other-array); #OUTPUT: Set.new(1,2,[3, 4])\ndd Set(@array, @other-array); #OUTPUT: Set.new(1,2,[3, 4])\ndd Set.new: @array, @other-array; #OUTPUT: Set.new([1, 2],[[3, 4],])\nRun Code Online (Sandbox Code Playgroud)\n不同的输出是故意的还是/Set.new中错误的结果?(我预计所有三个都会产生以下输出&setSetSet.new\xe2\x80\x93 生成的输出,我是否遗漏了一些关于预期语义的内容?)
set和之间的区别Set.new:仅是(未)扁平化的slurpy 参数*@a与 . 的区别**@a。
my @array = 1, 2;
my @other-array = ([3, 4],);
-> *@a { say @a }(@array, @other-array);
-> **@a { say @a }(@array, @other-array);
Run Code Online (Sandbox Code Playgroud)
Set()是胁迫。
my Set() $a = (@array, @other-array);
say $a;
-> Set() $a {say $a}( (@array, @other-array) );
say Set(Set(@array, @other-array)), (@array, @other-array).Set;
say Set(class :: { has (@.array, @.other-array); method Set () { set @!array, @!other-array } }.new( :@array, :@other-array ));
Run Code Online (Sandbox Code Playgroud)