Perl6运算符问题
我正在看愚蠢/可爱/辉煌的“睡眠排序”,它似乎起源于 4chan。要对整数数组进行排序,其想法大致是
foreach elt in @array spawn thread(elt)
thread(n) 执行的位置,
sleep n print n
以便更早地打印较小的值。
我知道有一个 Perl6 实现
@foo = @foo>>.&sleep;
>>
'hypers' 操作符,并且这假设 hypering 是自动并行化的。但 .&
让我感到困惑。
谁能解释一下吗?
谢谢
I was looking at the silly/cute/brilliant "sleep sort" that seems to have originated over at 4chan. To sort an array of ints, the idea is roughly
foreach elt in @array spawn thread(elt)
where thread(n) does
sleep n print n
so the smaller values get printed earlier.
There's a Perl6 implementation
@foo = @foo>>.&sleep;
I get that >>
'hypers' the operator, and that this assumes hypering is automatically parallelized. But the .&
confuses me.
Can anyone explain this?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有一个函数
yourfunc
,那么您可以使用与符号&yourfunc
获取对它的引用。语法$obj.$function
仅使用一个参数$obj
调用$function
。因此,人们也可以编写$function($obj)
- 只不过这种语法不允许使用 hyper。但是,无论谁提出这个“实现”,在三个方面都是错误的:
@foo
根本不会被排序,即使第一点不适用。If you have a function
yourfunc
, then you can grab a reference to it with the ampersand,&yourfunc
. The syntax$obj.$function
just invokes$function
with one argument,$obj
. So one could just as well write$function($obj)
- except that this syntax doesn't allow the use of a hyper.But whoever came up with this "implementation" was wrong on three accounts:
@foo
will not be sorted at all, even if the first point didn't apply.