gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:19:46 26 4
gpt4 key购买 nike

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
那么,我在这里做错了什么?

最佳答案

有两个问题。
首先,您需要添加 is assoc<chain>特性到你的子。
但是还是不行,因为有一个bug需要修复:Reduction with a function reference fails to honour chain associativity .

关于function - 使用用户定义函数错误的归约运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65374025/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com