在perl6中的方法声明中加号意味着什么?

问题描述 投票:5回答:2

Perl6中方法声明中加号的含义是什么?

这里是spec的示例

submethod BUILD (+$tail, +@legs, *%extraargs) {
    $.tail = $tail;
    @:legs = @legs; 
}
perl6 raku
2个回答
9
投票
可变位置分解; +@foo中的*@foomy answer to the SO question "variable number of arguments to function/subroutine"

[Larry Wall在2015年推出了+ parameter prefix,这是表示+的四个参数前缀(***+|)之一。他将其添加到Rakudo编译器中,添加了一些测试,给出了slurpy (variadic) parameters,并向相关的语言设计文档中添加了a brief informal description of it on the irc channel


原始问题中引用的示例摘自一份非正式文档的存档,该文档是在十年前及时编写并冻结的。那时a section on it参数前缀表示+。如今,我们为此使用a named parameter as contrasted with a positional one,因此:

:


9
投票
© www.soinside.com 2019 - 2024. All rights reserved.