超企业的奇怪行为

发布于 2025-01-18 04:59:33 字数 665 浏览 2 评论 0原文

我发现了超级运算符的这种奇怪行为:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤蝉 2025-01-25 04:59:33

这绝对是一个错误,因为:

my @a = 0, 0, 0;
say HYPER(&infix:<<!=>>, @a, @a);  # [False False False]

给出了正确的结果。但是,传递给 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:

my @a = 0, 0, 0;
say HYPER(&infix:<<!=>>, @a, @a);  # [False False False]

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文