解释器 (REPL) 中的 Perl 6 函数参数语法

Perl 6 function argument syntax in the interpreter (REPL)

解释器中的参数语法似乎有些不一致。我正在使用最新的 Rakudo。请查看以下终端输出:

$ perl6
To exit type 'exit' or '^D'
> say: "foo"
foo
> say("foo")
foo
> say "foo"
===SORRY!=== Error while compiling:
Two terms in a row
------> say⏏ "foo"
    expecting any of:
        infix
        infix stopper
        statement end
        statement modifier
        statement modifier loop
> 
$ perl6
To exit type 'exit' or '^D'
> say "foo"
foo
> say("foo")
foo
> say: "foo"
foo
> say "foo"
===SORRY!=== Error while compiling:
Two terms in a row
------> say⏏ "foo"
    expecting any of:
        infix
        infix stopper
        statement end
        statement modifier
        statement modifier loop
> 
$ 

看来你用了“:”或“()”来提供参数后,就不能再回去使用“了",即 space,以提供参数。

还是我漏掉了什么?

谢谢!!!

lisprog

say: "foo"

该行 调用 say 子例程。

相反,它声明了一个名为 saystatement label,然后执行语句 "foo"(什么都不做)。

它在你的例子中打印 "foo" 的唯一原因是因为你将它输入到 REPL 中,它会自动打印每行最后一条语句的值。

如果您在普通程序中使用它,它实际上会抛出警告 Useless use of constant string "foo" in sink context

say "foo" ===SORRY!=== Error while compiling: Two terms in a row ------> say⏏ "foo" expecting any of: infix infix stopper statement end statement modifier statement modifier loop

声明标签后,此范围内的符号 say 不再引用具有该名称的内置子例程,而是引用您的自定义标签,使用它是一个语法错误像这样的标签。

不过,错误消息应该能很好地解释这一点。我已经 submitted a Rakudo ticket 了。