2010/3/23 Moritz Lenz mor...@faui2k3.org:
Hi,
Hongwen Qiu wrote:
Hi, I'm new to Perl6. And just ran the first example in the perl6 book.
But, it refused to work. It complains as follows:
Too many positional parameters passed; got 2 but expected between 0 and 1
I find out that the problem is in the line:
my @sorted = @names.sort({ %sets{$_} }).sort({ %games{$_} }).reverse;
And I tried eliminate the second sort, or just the parameters in the
second sort. In both cases, it works.
So, why is this happen? Can it be a bug?
Yes. Thank you for your report.
Rakudo has gone through a major rewrite, and in that process some of the
features have temporarily disappeared. .sort() with a block accepting
just one parameter is one of these features.
Actually, as we just determined on #perl6, it works normally, and only
fails under certain conditions -- basically when you get a low-level
collection of things rather than something based on the Perl 6 Seq or
Iterator classes. So there is a fairly simple workaround:
colomon: rakudo: say (-5...10).sort({.abs}).sort({.abs}).perl
p6eval: rakudo db0f85: OUTPUT«Too many positional parameters passed;
got 2 but expected between 0 and 1current instr.: '_block68' pc -1
((unknown file):-1)»
colomon: rakudo: say (-5...10).sort({.abs}).Seq.sort({.abs}).perl
p6eval: rakudo db0f85: OUTPUT«(0, -1, 1, -2, 2, -3, 3, -4, 4, -5, 5,
6, 7, 8, 9, 10)»
That is, adding a .Seq between the two sorts clears up the problem.
That is admittedly a hack, but it is a simple one.
Thanks for reporting the problem!
--
Solomon Foster: colo...@gmail.com
HarmonyWare, Inc: http://www.harmonyware.com