perl6/rakudo:无法解析 postcircumfix:sym<( )>

发布于 2024-10-17 23:35:54 字数 278 浏览 5 评论 0 原文

为什么我会收到此错误消息?

#!perl6
use v6;

my @a = 1..3;
my @b = 7..10;
my @c = 'a'..'d';


for zip(@a;@b;@c) -> $nth_a, $nth_b, $nth_c { ... };


# Output:

# ===SORRY!===
# Unable to parse postcircumfix:sym<( )>, couldn't find final ')' at line 9

Why do I get this error-message?

#!perl6
use v6;

my @a = 1..3;
my @b = 7..10;
my @c = 'a'..'d';


for zip(@a;@b;@c) -> $nth_a, $nth_b, $nth_c { ... };


# Output:

# ===SORRY!===
# Unable to parse postcircumfix:sym<( )>, couldn't find final ')' at line 9

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

滥情哥ㄟ 2024-10-24 23:35:54

Rakudo 尚未实现 lol(“列表的列表”)形式,因此无法解析 @a;@b;@c。出于同样的原因,zip 还没有包含三个列表的表单。显然,错误消息不太好。

目前还没有真正好的解决方法,但这里有一些可以完成工作的方法:

sub zip3(@a, @b, @c) {
    my $a-list = flat(@a.list);
    my $b-list = flat(@b.list);
    my $c-list = flat(@c.list);
    my ($a, $b, $c);
    gather while ?$a-list && ?$b-list && ?$c-list {
        $a = $a-list.shift unless $a-list[0] ~~ ::Whatever;
        $b = $b-list.shift unless $b-list[0] ~~ ::Whatever;
        $c = $c-list.shift unless $c-list[0] ~~ ::Whatever;
        take ($a, $b, $c);
    }
}

for zip3(@a,@b,@c) -> $nth_a, $nth_b, $nth_c {
    say $nth_a ~ $nth_b ~ $nth_c;
}

Rakudo doesn't implement the lol ("list of lists") form yet, and so cannot parse @a;@b;@c. For the same reason, zip doesn't have a form which takes three lists yet. Clearly the error message is less than awesome.

There isn't really a good workaround yet, but here's something that will get the job done:

sub zip3(@a, @b, @c) {
    my $a-list = flat(@a.list);
    my $b-list = flat(@b.list);
    my $c-list = flat(@c.list);
    my ($a, $b, $c);
    gather while ?$a-list && ?$b-list && ?$c-list {
        $a = $a-list.shift unless $a-list[0] ~~ ::Whatever;
        $b = $b-list.shift unless $b-list[0] ~~ ::Whatever;
        $c = $c-list.shift unless $c-list[0] ~~ ::Whatever;
        take ($a, $b, $c);
    }
}

for zip3(@a,@b,@c) -> $nth_a, $nth_b, $nth_c {
    say $nth_a ~ $nth_b ~ $nth_c;
}
篱下浅笙歌 2024-10-24 23:35:54

多维语法(在括号内使用 ; )和跨越两个以上列表的 zip 都可以工作,因此最初发布的代码现在可以工作(如果您提供一些真实的代码而不是 { ... } 存根块)。

The multi-dimensional syntax (the use of ; inside parens) and zip across more than two lists both work, so the code originally posted now works (if you provide some real code rather than the { ... } stub block).

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