# New Ticket Created by Vasily Chekalkin # Please include the string: [perl #63712] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=63712 >
--- src/builtins/any-list.pir | 47 --------------------------------------------- src/setting/Any-list.pm | 20 ++++++++++++++++++- 2 files changed, 19 insertions(+), 48 deletions(-)
diff --git a/src/builtins/any-list.pir b/src/builtins/any-list.pir index b87666b..bc5cc9e 100644 --- a/src/builtins/any-list.pir +++ b/src/builtins/any-list.pir @@ -223,53 +223,6 @@ Return a List with the keys of the invocant. .return(res) .end -=item min - -=cut - -.namespace [] -.sub 'min' :multi() - .param pmc values :slurpy - .local pmc by - by = get_hll_global 'infix:cmp' - unless values goto have_by - $P0 = values[0] - $I0 = isa $P0, 'Sub' - unless $I0 goto have_by - by = shift values - have_by: - .tailcall values.'min'(by) -.end - - -.namespace ['Any'] -.sub 'min' :method :multi(_) - .param pmc by :optional - .param int has_by :opt_flag - if has_by goto have_by - by = get_hll_global 'infix:cmp' - have_by: - - .local pmc it, result - $P0 = self.'list'() - it = $P0.'iterator'() - unless it goto fail - result = shift it - loop: - unless it goto done - $P0 = shift it - $I0 = by($P0, result) - unless $I0 < 0 goto loop - result = $P0 - goto loop - fail: - .local num failres - failres = "+Inf" - .return (failres) - done: - .return (result) -.end - .namespace [] .sub 'max' :multi() diff --git a/src/setting/Any-list.pm b/src/setting/Any-list.pm index 5758dce..0aaeccc 100644 --- a/src/setting/Any-list.pm +++ b/src/setting/Any-list.pm @@ -23,7 +23,20 @@ class Any is also { $res = &$expression($res, |@args); } $res; - } + }; + + # RT #63700 - parse failed on &infix:<cmp> + our Array multi method min( $values: Code $by = sub { $^a cmp $^b } ) { + my @list = $values.list; + return +Inf unless @list.elems; + my $res = @list.shift; + for @list -> $x { + if (&$by($res, $x) > 0) { + $res = $x; + } + } + $res; + }; } our List multi grep(Code $test, *...@values) { @@ -34,4 +47,9 @@ multi reduce ( Code $expression ;; *...@values ) { @values.reduce($expression); } +our List multi min(*...@values) { + my $by = @values[0] ~~ Code ?? shift @values !! sub { $^a cmp $^b }; + @values.min($by); +} + # vim: ft=perl6