I will start this off with the three from masak's journal:my @fibs := (0, 1, -> $a, $b { $a + $b } ... *);my @fibs := (0, 1, { $^a + $^b } ... *); my @fibs := (0, 1, *+* ... *);我在想类似的方法也可以,但是我认为我的语法有误:I was thinking something like this would also work, but I think I have the syntax wrong:my @fibs := (0, 1, (@fibs Z+ @fibs[1..*]));急切的东西(切片?)使Rakudo进入无限循环.这是Haskell定义的翻译:Something there is eager (the slice?) and causes Rakudo to enter an infinite loop. It's a translation of the Haskell definition:fibs = 0 : 1 : zipWith (+) fibs (tail fibs)更新:好像zipWith示例的问题是@fibs[1..*] slice.如果tail被定义为sub tail (@x) {my $i = 1; {@x[$i++]}...*},则它可以正常工作.我很想知道为什么熟悉乐天(Rakudo)内部原理的人都不会对这种切片感到懒惰.Seems like the problem with the zipWith example is the @fibs[1..*] slice. if tail is defined as sub tail (@x) {my $i = 1; {@x[$i++]}...*} then it works properly. I would be interested to know why the slice isn't lazy from anyone familiar with Rakudo's internals.另一个不错的是:my @fibs := (0, [\+] 1, @fibs);推荐答案最短的似乎是my @fibs := ^2,*+*...*; 这篇关于有多少种方法可以描述Perl 6中的斐波那契数列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-20 05:02