超企业的奇怪行为
我发现了超级运算符的这种奇怪行为:
say 0 != 0; # False
my @a = 0, 0, 0;
say @a «==» @a; # [True True True]
say @a «!=» @a; # [True True True] <--- why?
say @a «!==» @a; # [False False False]
!=
中缀运算符定义为 这里相当于!==,但显然不是,至少在超级运算符中使用时是这样。
该问题似乎与特定值(零)有关,因为使用不同的值会返回预期结果。 此外,使用 0 but True
效果很好:
@a = 0 but True, 0 but True, 0 but True;
say @a «!=» @a; # [False False False]
我正在使用 Rakudo 2022.03。
这是一个错误还是我无法理解的东西?
I found out this strange behavior of a hyperoperator:
say 0 != 0; # False
my @a = 0, 0, 0;
say @a «==» @a; # [True True True]
say @a «!=» @a; # [True True True] <--- why?
say @a «!==» @a; # [False False False]
The !=
infix operator is defined here as equivalent to !== while apparently it's not, at least when used in a hyperoperator.
The problem seems to be related to the specific value (zero), since using a different value returns the expected result.
Besides, using 0 but True
works fine:
@a = 0 but True, 0 but True, 0 but True;
say @a «!=» @a; # [False False False]
I'm using Rakudo 2022.03.
Is this a bug or something I cannot grasp?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这绝对是一个错误,因为:
给出了正确的结果。但是,传递给
HYPER
的不是&infix:<>
,而是一个代码块显然(错误地)包裹了它。进一步调查,但是请,是的,这是一个错误,因此应该报告:-)
编辑: https://github.com/rakudo/rakudo/issues/4838
编辑:https://github.com/rakudo/rakudo/pull/4839 修复了它,但不确定它的修复方式:-)
编辑:修复已由 jnthn 批准,合并。将于2022.04。感谢您的关注!
It most definitely is a bug, as this:
gives the correct result. However, what gets passed to
HYPER
is not the&infix:<<!=>>
, but a code block that apparently wraps it (incorrectly).Investigating further, but please, yes, this is a bug and as such should be reported :-)
EDIT: https://github.com/rakudo/rakudo/issues/4838
EDIT: https://github.com/rakudo/rakudo/pull/4839 fixes it, but am unsure about the way it fixes it :-)
EDIT: Fix has been approved by jnthn, merged. Will be in 2022.04. Thanks for noting!