Categories

Posts in this category

Sun, 17 Oct 2010

This Week's Contribution to Perl 6 Week 11: Improve an error message for Hyper Operators


Permanent link

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.

# equal length required:
say join ', ', (1, 2, 3) >>+<< (10, 20, 30);
# output: 11, 22, 33

# auto-extending the right side by
# turning the less-then/larger-then signs around:
say join ', ', (1, 2, 3) >>+>> 10;
# output: 11, 12, 13

# this correctly produces an error message
(1, 2, 3) >>+<< (1, 2)
# output: Sorry, sides are of uneven length and not dwimmy.

# recurses into structures
((1, 2, [3, 4]) >>+<< (10, 10, [20, 20])).perl
#output: [11, 12, [23, 24]]

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@faui2k3.org 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".

[/perl-6] Permanent link

comments / trackbacks