Dave Whipp wrote:
According to S29, the "min" and "max" methods should accept the same
ordering args as "sort":
say "{(1..10).sort: { ($_-3) * ($_-5) }}";
4 3 5 2 6 1 7 8 9 10
say (1..10).min: { ($_-3) * ($_-5) };
4
Attached patch for fixing Range.min, max and minmax.
Spectest updated in r25027.
--
Bacek
commit 765c12dc6eb733b87e190ce39519af978ad66a79
Author: Vasily Chekalkin <ba...@bacek.com>
Date: Mon Jan 26 09:20:45 2009 +1100
Proper implement min, max and minmax on Ranges.
diff --git a/languages/perl6/src/classes/Range.pir b/languages/perl6/src/classes/Range.pir
index a3bc69e..9298f89 100644
--- a/languages/perl6/src/classes/Range.pir
+++ b/languages/perl6/src/classes/Range.pir
@@ -136,19 +136,43 @@ just return a clone of the Range.
.namespace ['Range']
-.sub 'max' :method
+.sub 'max' :method :multi(_)
+ .param pmc by :optional
+ .param int has_by :opt_flag
+ if has_by goto have_by
.tailcall self.'to'()
+
+ have_by:
+ # Flatten range and delegate call Array.max
+ $P0 = self.'list'()
+ .tailcall $P0.'max'(by)
.end
-.sub 'min' :method
+.sub 'min' :method :multi(_)
+ .param pmc by :optional
+ .param int has_by :opt_flag
+ if has_by goto have_by
.tailcall self.'from'()
+
+ have_by:
+ # Flatten range and delegate call Array.min
+ $P0 = self.'list'()
+ .tailcall $P0.'min'(by)
.end
-.sub 'minmax' :method
+.sub 'minmax' :method :multi(_)
+ .param pmc by :optional
+ .param int has_by :opt_flag
+ if has_by goto have_by
$P0 = self.'from'()
$P1 = self.'to'()
$P2 = get_hll_global 'list'
.tailcall $P2($P0, $P1)
+
+ have_by:
+ # Flatten range and delegate call Array.minmax
+ $P0 = self.'list'()
+ .tailcall $P0.'minmax'(by)
.end