New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reimplement List.min in Perl6 instead of PIR #754
Comments
From @baceksrc/builtins/any-list.pir | 47 --------------------------------------------- |
From @bacek059ec2c89dc266165efcee344f248218be567fe4.diffdiff --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
|
From @moritzOn Sat Mar 07 21:50:00 2009, bacek wrote:
Applied as a7214ac28c5c7c47932f1e76a15c8707524f964d, thanks. Moritz |
The RT System itself - Status changed from 'new' to 'open' |
@moritz - Status changed from 'open' to 'resolved' |
@pmichaud - Status changed from 'resolved' to 'open' |
From @pmichaudOn Sat, Mar 07, 2009 at 09:50:02PM -0800, Vasily Chekalkin wrote:
This doesn't match the spec -- the $by parameter is required. Yes, the PIR code was "cheating" in this respect, but I don't
Why are C<min> and C<max> specced as returning C<Array> and C<List>? Pm |
From @moritzPatrick R. Michaud wrote:
I've fixed that, and corrected the spec tests accordingly.
I agree, so I removed the non-sense return types from the specs. Cheers, |
From @bacekPatrick R. Michaud via RT wrote:
This is workaround for this situation: <bacek> rakudo: multi sub foo(Code &x, *@values) {...}; multi sub Should I fill bug report for this? -- |
From @pmichaudOn Mon Mar 09 00:41:24 2009, bacek wrote:
Yes please. Closing this ticket, thanks! Pm |
@pmichaud - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#63712 (status was 'resolved')
Searchable as RT63712$
The text was updated successfully, but these errors were encountered: