gpt4 book ai didi

new-operator - 创建新运算符(operator)

转载 作者:行者123 更新时间:2023-12-03 01:26:08 25 4
gpt4 key购买 nike

我正在尝试将 Ø 设为逻辑否定运算符。

¬ True;

multi sub prefix:<¬> ($n) {
return not $n;
}

当我运行上面的程序时,它返回以下错误:

$ perl6 test.pl6  
===SORRY!=== Error while compiling /home/devXYZ/test.pl6 Bogus statement at /home/devXYZ/test.pl6:1
------> <BOL>⏏¬ True;
expecting any of:
prefix
term

有谁知道是什么原因吗?

最佳答案

new 运算符的声明必须出现在其使用之前。将程序更改为:

multi sub prefix:<¬> ($n) {
return not $n;
}
say ¬ True;

让它工作正常。

Perl 6 具有严格的一次性解析规则。因此,顺序对于影响正在解析的语言的任何事情都很重要 - 例如通过引入类型或新运算符。

关于new-operator - 创建新运算符(operator),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49470970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com