看起来maxpairs不喜欢在具有未定义值的列表上调用:
> my @foo; @foo[2] = 4; say @foo.maxpairs;
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
in block <unit> at <unknown file> line 1
(2 => 4)
Run Code Online (Sandbox Code Playgroud)
max 没有相同的问题,似乎只是忽略未定义的值:
> my @foo; @foo[2] = 4; say @foo.max;
4
Run Code Online (Sandbox Code Playgroud)
发生同样的错误:
> my @foo; @foo[2] = 4; say @foo.pairs.max(*.value)
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
in block <unit> at <unknown file> line 1
2 => 4
Run Code Online (Sandbox Code Playgroud)
因此,只有在max没有filter参数的情况下使用时,才会忽略未定义的值.
这是一个错误吗?
由于这看起来像一个bug,我已经修复了它
https://github.com/rakudo/rakudo/commit/7bf7a2c6f83a57713c
Run Code Online (Sandbox Code Playgroud)
这也照顾"minpairs".