使用 Perl 6 Sequence Another (...) 运算符进行乘法
我已经看到了序列中 Perl 6whatever (...) 运算符的示例,并且我尝试找出如何执行涉及乘法的序列。
该运算符执行以下操作,如果以一些数字开头,则可以指定其后面的数字序列。
@natural = 1,2 ... *;
@powersOfTwo = 1,2,4 ... *;
等等。 人们还可以使用序列中的前一个数字来定义一个序列,如斐波那契数列(如本问题所示),其中一个执行以下操作:
@fibonacci = 1,1, *+* ... *;
问题是乘法运算符是 *
并且前面的数字也用 *
表示。
虽然我可以使用 +
、-
和 /
定义序列,但我似乎找不到使用 定义序列的方法*。
我已经尝试过以下方法:
@powers = 1,2, *** ... *;
但显然不起作用。
有谁知道如何做到这一点?
I have seen examples of the Perl 6 whatever (...) operator in sequences, and I have tried to find out how to do a sequence which involves multiplications.
The operator does the following, if one starts with some numbers, one can specify a sequence of the numbers following it.
@natural = 1,2 ... *;
@powersOfTwo = 1,2,4 ... *;
and so on.
One could also define a sequence using the previous numbers in the sequence as in the fibonacci numbers (shown in this question), where one does the following:
@fibonacci = 1,1, *+* ... *;
The problem is that the multiplication operator is *
and the previous numbers are also represented with *
.
While I can define a sequence using +
, -
and /
, I can not seem to find a way of defining a sequence using *
.
I have tried the following:
@powers = 1,2, *** ... *;
but it obviously does not work.
Does anyone know how to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一方面,Perl 6 对空格很敏感。
是完全合法的,并且生成一个有点像乘法斐波那契的序列;只是有点难读。
***
和* * *
的含义不同。如果歧义困扰您,您可以使用显式块,而不是使用“无论星号”给您提供的隐式块:
并且
两者都会产生与
1, 2, * * * ... * 相同的序列> 确实(在 Rakudo 中测试)。
For one thing, Perl 6 is sensitive to whitespace.
is perfectly legitimate and generates a sequence that's sort of like a multiplicative fibonacci; it's just a little bit hard to read.
***
and* * *
mean something different.If the ambiguity bothers you, you can use an explicit block instead of the implicit one that using "whatever star" gives you:
and
both produce the same sequence as
1, 2, * * * ... *
does (tested in Rakudo).