Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl 6: maxpairs warns about stringification of undefined values

Tags:

raku

rakudo

It looks like maxpairs doesn't like to be called on a list with undefined values:

> my @foo; @foo[2] = 4; say @foo.maxpairs;
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
  in block <unit> at <unknown file> line 1

(2 => 4)

max doesn't have the same issue and seems to simply ignore undefined values:

> my @foo; @foo[2] = 4; say @foo.max;
4

The same error does occur with:

> my @foo; @foo[2] = 4; say @foo.pairs.max(*.value)
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
  in block <unit> at <unknown file> line 1

2 => 4

So it appears that undefined values are only ignored when using max without a filter parameter.

Is this a bug?

like image 330
mscha Avatar asked Dec 09 '18 13:12

mscha


1 Answers

Since this looks like a bug, I've fixed it with

https://github.com/rakudo/rakudo/commit/7bf7a2c6f83a57713c

Which also takes care of "minpairs".

like image 186
Elizabeth Mattijsen Avatar answered Oct 21 '22 20:10

Elizabeth Mattijsen