Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl6/rakudo: Unable to parse postcircumfix:sym<( )>

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
like image 862
sid_com Avatar asked Feb 17 '11 08:02

sid_com


2 Answers

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;
}
like image 182
Sol Avatar answered Nov 06 '22 04:11

Sol


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).

like image 30
raiph Avatar answered Nov 06 '22 03:11

raiph