相关疑难解决方法(0)

在Perl 6中使用方法和函数调用冒号

我想知道冒号与Perl 6中的方法和函数调用有什么关系.对于记录,我使用的是基于MoarVM版本2015.05构建的perl6版本2015.05-55-gd84bbbc.

我刚刚在Perl6规范测试中看到了以下内容(S32-io)(我添加了评论):

$fh.print: "0123456789A";   # prints '0123456789A' to the file
Run Code Online (Sandbox Code Playgroud)

据我所知,这相当于:

$fh.print("0123456789A");   # prints '0123456789A' to the file
Run Code Online (Sandbox Code Playgroud)

这两个似乎都采取了多个参数并平整列表:

$fh.print: "012", "345", "6789A";   # prints '0123456789A' to the file
$fh.print("012", "345", "6789A");   # prints '0123456789A' to the file

my @a = <012 345 6789A>;

$fh.print(@a);   # prints '0123456789A' to the file
$fh.print: @a;   # prints '0123456789A' to the file
Run Code Online (Sandbox Code Playgroud)

必须有一些理由拥有这两种不同的语法.有没有理由使用一种或另一种语法?

我还注意到,当用作方法时,我们必须使用:()使用print:

$fh.print(@a);   # Works
$fh.print: @a;   # Works!
$fh.print @a;    # …
Run Code Online (Sandbox Code Playgroud)

perl6

6
推荐指数
2
解决办法
435
查看次数

标签 统计

perl6 ×1