Parrot是最初为Perl 6设计的虚拟机.
Parrot VM提供哪些技术功能,如Java虚拟机(JVM)/热点VM和公共语言运行时(CLR)等竞争虚拟机缺乏?
在阅读有关Perl 6的内容时,我看到一个被大肆宣扬的功能,您不再需要这样做:
return "0 but true";
Run Code Online (Sandbox Code Playgroud)
...但可以改为:
return 0 but True;
Run Code Online (Sandbox Code Playgroud)
如果是这样的话,Perl 6中的真相如何运作?在Perl 5中,它很简单:0,""和undef都是假的,其他一切都是真的.
在布尔上下文中,Perl 6中有哪些规则?
有一个练习,我需要定义阿克曼函数。
我定义了一个正整数子集:
subset Positive-Integer of Int where { $_ > 0}
Run Code Online (Sandbox Code Playgroud)
然后我使用以下方法遍历递归版本:
multi ackermann(0, Positive-Integer $n) {
$n + 1;
}
multi ackermann(Positive-Integer $m, 0) {
ackermann $m - 1, 1;
}
multi ackermann(Positive-Integer $m, Positive-Integer $n) {
ackermann $m - 1, ackermann $m, $n - 1;
}
Run Code Online (Sandbox Code Playgroud)
但是执行我在执行时得到的代码:
阿克曼 3, 4;
> * * &ackermann
> > * * &ackermann
> > * * &ackermann
> > ackermann 3, 4
Cannot resolve caller ackermann(Int:D, …
Run Code Online (Sandbox Code Playgroud) 有时我会在Perl 6 REPL上开始编写方法调用链,例如:
".".IO.dir.grep(...).map(...).
Run Code Online (Sandbox Code Playgroud)
...然后我意识到我要对最终列表进行的操作是将每个元素打印在自己的行上。我希望序列具有某种each
方法,因此我可以使用结束链.each(*.say)
,但是没有找到这样的方法。取而代之的是,我必须返回到该行的开头并前置.say for
。感觉好像打乱了我的思想。
这是一个小麻烦,但是却让我感到震惊,我不知道我是否缺少一些简单的选择。我唯一想到的是».say
and .join("\n").say
,但是前者可以对元素进行无序操作(如果我理解正确的话),而后者可以构造一个字符串,该字符串可能会很大,具体取决于输入列表。
我想生成的序列
1, 1/2, 1/3, 1/4 ... *
Run Code Online (Sandbox Code Playgroud)
在 raku 中使用函数式编程方法,在我的脑海中它应该是这样的:
(1,{1/$_} ...*)[0..5
]
但输出是: 1,1,1,1,1 这个想法很简单,但对我来说似乎足够强大,可以用来生成其他复杂的列表并使用它。
我尝试过的其他事情是使用惰性列表在其他惰性列表中调用,它也不起作用,因为输出是重复序列:1, 0.5, 1, 0.5 ...
my list = 0 ... *;
(1, {1/@list[$_]} ...*)[0..5]
Run Code Online (Sandbox Code Playgroud) 如何在Perl 6中表达双变量双求和序列?
有关双变量双求和序列的示例,请参见此
它必须按原样表示,即在数学上不将双重求和简化为单一求和。谢谢。
我很好奇为什么 Raku 在操作多维数组时表现如此糟糕。我在 Python、C# 和 Raku 中做了一个初始化二维矩阵的快速测试,而后者的耗用时间非常高。
对于乐
my @grid[4000;4000] = [[0 xx 4000] xx 4000];
# Elapsed time 42 seconds !!
Run Code Online (Sandbox Code Playgroud)
对于 Python
table= [ [ 0 for i in range(4000) ] for j in range(4000) ]
# Elapsed time 0.51 seconds
Run Code Online (Sandbox Code Playgroud)
C#
int [,]matrix = new int[4000,4000];
//Just for mimic same behaviour
for(int i=0;i<4000;i++)
for(int j=0;j<4000;j++)
matrix[i,j] = 0;
# Elapsed time 0.096 seconds
Run Code Online (Sandbox Code Playgroud)
我做错了吗?好像差别太大了。
我有一个数组:
my @e = <60.922 20.946 8.721 7.292 4.306 2.821 2.765 2.752 2.741 2.725>
Run Code Online (Sandbox Code Playgroud)
我想将数组中的每个元素除以最小值,但是
@e /= @e.min
Run Code Online (Sandbox Code Playgroud)
产生了单个元素,这是不正确的。
我已阅读https://docs.raku.org/type/Array但我不了解 Raku 的基本元素。
如何将数组中的每个项目除以相同的数字?
我想了解如何开始使用Perl 6?是否可以使用正在Parrot上构建的Rakudo,或者更好地使用Pugs实现?
如果Rakudo,安装它的最佳方法是什么?鹦鹉的每月发布,鹦鹉的SVN,其他?
我想在映射例程中使用数组的索引。例如,这个 Raku 代码:
raku -e 'my @a = "First", "Second", "Third", "First"; say @a.map({ "Index of $_ is: ;" })'
印刷:
(Index of First is: ; Index of Second is: ; Index of Third is: ; Index of First is: ;)
是否可以获取数组的索引,例如:
(Index of First is: 0; Index of Second is: 1; Index of Third is: 2; Index of First is: 3;)
谢谢!
raku ×10
perl6 ×4
parrot ×2
clr ×1
dictionary ×1
jvm ×1
math ×1
performance ×1
pugs ×1
rakudo ×1
truthiness ×1