gpt4 book ai didi

raku - 标签和 "Control flow commands not allowed in toplevel"(可能的 LTA 错误消息)

转载 作者:行者123 更新时间:2023-12-04 14:22:17 24 4
gpt4 key购买 nike

这段代码:

FOO:
"Hey".say;
for <1 2> {
say "1";
last FOO
}

打印
Hey
1
Control flow commands not allowed in toplevel

如果去掉“Hey”.say,则消除最后一条错误信息;这可能意味着错误实际上是在说标签后面不允许非控制流命令。但是 the documentation (其中 needs to be improved 引用循环作为“示例”,而 the grammar 表示它应该在语句的前面。所以问题是:它可以用于 if 语句,还是仅用于循环?

最佳答案

如果您在另一个范围内使用此代码,则错误会有所不同:

{
FOO:
"Hey".say;
for <a b> {
.say;
last FOO
}
}
# Hey
# a
# labeled last without loop construct

这也是 LTA,因为它没有提到标签的名称。

但简而言之:Perl 6 目前没有 goto .目前,标签仅可用作指定要使用哪个循环构造的方式 next , redolast在......之外。通过在标签和循环结构之间放置一个语句,您可以有效地将它用作 goto ,尚未实现。

但确实有一张关于这两个错误的 LTAness 的票,对我来说似乎已经到位。

另外,使用 FIRST作为替代方案的移相器,似乎有同样的问题:
FOO:
for <a b> {
FIRST "Hey".say;
.say;
last FOO;
}
# Hey
# a
# labeled last without loop construct

但是在没有特定标签的情况下运行良好:
FOO:
for <a b> {
FIRST "Hey".say;
.say;
last;
}
# Hey
# a

后一期绝对值得一期 rakudo 问题:添加为 https://github.com/rakudo/rakudo/issues/2699 .

关于raku - 标签和 "Control flow commands not allowed in toplevel"(可能的 LTA 错误消息),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54706310/

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