单词 'if' 解释为 'if()' 函数调用。 Parens不允许

Word 'if' interpreted as 'if()' function call. Parens not allowed

所以我发现在 Perl 6 中写一个带括号的 if 语句会导致它向我抛出这个错误:

===SORRY!===
Word 'if' interpreted as 'if()' function call; please use whitespace instead of parens
at C:/test.p6:8
------> if<HERE>(True) {
Unexpected block in infix position (two terms in a row)
at C:/test.p6:8
------> if(True)<HERE> {

这让我假设存在某种 if() 函数?但是,创建并 运行 一个包含 if(); 的脚本会产生以下编译器错误:

===SORRY!===
Undeclared routine:
    if used at line 15

所以怎么回事?

我在这里 https://en.wikibooks.org/wiki/Perl_6_Programming/Control_Structures#if.2Funless 读到 parens 是可选的,但对我来说似乎并非如此。

我的 if 语句在没有 parens 的情况下也能正常工作,只是想知道为什么它会阻止我使用它们,或者为什么它会认为 if 是因为它们的子例程。

编辑: 好吧,我是不是有点傻...看起来我在 link I link 阅读得不够好ed 我想这就是你感到困惑的原因。 link 我 linked 指出了以下基本上是我要问的内容:

if($x > 5) {   # Calls subroutine "if"
}

if ($x > 5) {  # An if conditional
}

我接受了以下答案,因为它确实提供了一些见解。

您确定您创建了一个名为 'if' 的子程序吗?如果是这样,(没有双关语意),如果你在文字 'if' 之后使用 space,你将获得关键字,否则如果你在文字 [=29] 之后使用括号,你将获得预先声明的函数=] - 即,如果您对该术语的使用看起来像一个函数调用 - 并且您已经声明了这样一个函数 - 它会调用它;

use@localhost:~$ perl6
> sub if(Str $s) { say "if sub says: arg = $s" };
sub if (Str $s) { #`(Sub|95001528) ... }
> if "Hello World";
===SORRY!=== Error while compiling <unknown file>
Missing block
at <unknown file>:1
------> if "Hello World"⏏;
    expecting any of:
        block or pointy block
> if("Hello World");
if sub says: arg = Hello World
>
> if 12 < 16 { say "Excellent!" }
Excellent!
>

你可以在上面看到,我已经声明了一个名为 'if' 的函数。

if "Hello World"; 错误,因为 space 意味着我正在使用关键字,因此我们在尝试使用 if 关键字时遇到语法错误。

if("Hello World")成功调用预声明函数

if 12 < 18 { say "Excellent!" } 正常工作,因为 space 意味着 'if' 被解释为关键字,这次没有语法错误。

那么,你确定你有(或者更好 - 你能粘贴在这里)你预先声明的 'if' 函数吗?

关键字和whitespace(顺便以关键字'if'为例!)的参考在这里:SO2 - Keywords and whitespace