For this week's contribution to Perl 6 we ask you to improve the error message that Hyper Operators emit when lists are not of equal length.

(Introduction to this series of challenges)

Background

In Perl 6, operators can be applied to lists; in one version, the lists must be of equal length, in the other form one or more lists are automatically repeated to be of proper length.

say join ' , ' , ( 1 , 2 , 3 ) >>+<< ( 10 , 20 , 30 ) ; say join ' , ' , ( 1 , 2 , 3 ) >>+>> 10 ; ( 1 , 2 , 3 ) >>+<< ( 1 , 2 ) (( 1 , 2 , [ 3 , 4 ]) >>+<< ( 10 , 10 , [ 20 , 20 ])) . perl

What you can do

Please submit a patch that improves the error message. A good better error message would be:

# for non-recursive structures: Sorry, structures on both sides of non-dwimmy hyperop are not of same shape left: 3 elements right: 2 elements # for recursive structures: Sorry, structures on both sides of non-dwimmy hyperop are not of same shape left: 3 elements right: 2 elements at nesting level 2

The source code can be found in src/core/metaops.pm, spread out over a few multi subs.

You'll need to introduce another (probably named) parameter or a contextual variable to track the recursion depth.

Submission

Update: I have received one submission, worked a bit on it and included it in Rakudo.

Please submit your patch to the perl6-compiler@perl.org mailing list (and put moritz.lenz@gmail.com on CC, because the mailing list sometimes lags quite a bit).

If you have any questions, feel free to send them to the mailing list, or ask on our IRC channel".