使用用户定义函数错误的归约运算符

lis*_*tor 5 function reduction operator-keyword raku

raku 网页表示,应在归约运算符中为用户定义的函数使用额外的括号:https : //docs.raku.org/language/operators#Reduction_metaoperators

但是,当我将函数作为变量传递时出现错误(我使用的是 Rakudo Star 2010.10):

> sub lessThan ($a, $b) { $a < $b }
&lessThan
> my @a = ((1,2,3), (6,5,4))
[(1 2 3) (6 5 4)]
> sub x (@arrOfArr, &func) { say @arrOfArr.grep( { [[&func]] ($_[0], $_[1], $_[2]) } ); }
&x
> x(@a, &lessThan)
((1 2 3) (6 5 4)) # <----------------------------------- this is not what I expected
> say @a.grep( { [<] ($_[0], $_[1], $_[2]) } );
((1 2 3)) # <------------------------------------------- this is what I want
Run Code Online (Sandbox Code Playgroud)

那么,我在这里做错了什么?

rai*_*iph 5

有两个问题。

首先,您需要将is assoc<chain>特征添加到您的子项中。

但它仍然不起作用,因为有一个错误需要修复:使用函数引用进行归约无法遵守chain关联性