您好我正在尝试在https://docs.perl6.org/language/operators#Hyper_operators中使用分配超级运算符Perl 6
?my (@one, @two) «=» (<1 2 3>,<4 5 6>);
say @one;
say @two;
# Prints nothing (empty array)
# Expected behaviour:
@one=<1 2 3>;
@two=<4 5 6>;
say @one;
say @two;
# Prints [1 2 3] and [4 5 6]
Run Code Online (Sandbox Code Playgroud)
如何使分配超级操作员正确运行?谢谢。
Hol*_*lli 10
你近了 在我们发现的文档中仅一点点
zip元运算符(与Z不同)将给定的中缀运算符应用于从其参数向左,向右截取的对。
所以
my (@one, @two) Z= <1 2 3>, <4 5 6>;
Run Code Online (Sandbox Code Playgroud)
这是在当前开发人员版本上运行的基准。它将上面的“魔术”变量与两个顺序分配进行比较。
use v6;
use Benchmark;
my %results = timethese(100000, {
"magic" => sub { my (@one, @two) Z= <1 2 3>, <4 5 6> },
"plain" => sub { my @one = <1 2 3>; my @two = <4 5 6> },
});
say ~%results;
# magic 1569668462 1569668464 2 0.00002
# plain 1569668464 1569668464 0 0
Run Code Online (Sandbox Code Playgroud)