Skip to content
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

Implementation of List.min and List.max #123

Closed
p6rt opened this issue Jun 8, 2008 · 5 comments
Closed

Implementation of List.min and List.max #123

p6rt opened this issue Jun 8, 2008 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 8, 2008

Migrated from rt.perl.org#55482 (status was 'resolved')

Searchable as RT55482$

@p6rt
Copy link
Author

p6rt commented Jun 8, 2008

From @bacek

Hello.

There is implementation of List.min and List.max

--
Bacek

@p6rt
Copy link
Author

p6rt commented Jun 8, 2008

From @bacek

minmax.diff
diff --git a/languages/perl6/src/classes/List.pir b/languages/perl6/src/classes/List.pir
index b9b5107..3b6fe2a 100644
--- a/languages/perl6/src/classes/List.pir
+++ b/languages/perl6/src/classes/List.pir
@@ -684,6 +686,107 @@
 .end
 
 
+=item min()
+
+Return minimum element in list
+
+=cut
+
+.sub 'min' :method :multi('ResizablePMCArray')
+    .param pmc by              :optional
+    .param int has_by          :opt_flag
+    .local pmc elem, res, iter
+
+    if has_by goto start
+    by = get_hll_global 'infix:<=>'
+  start:
+    iter = self.'iterator'()
+    if iter goto do_work
+    res = new 'Failure'
+    goto done
+
+  do_work:
+    res = shift iter
+  loop:
+    unless iter goto done
+    elem = shift iter
+    $I0 = by(elem, res)
+    unless $I0 < 0 goto loop
+    res = elem
+    goto loop
+
+  done:
+    .return(res)
+.end
+
+.namespace []
+.sub 'min' :multi(Closure)
+    .param pmc by
+    .param pmc values          :slurpy
+    $P0 = values.'min'(by)
+    .return ($P0)
+.end
+
+.sub 'min' :multi()
+    .param pmc values          :slurpy
+    .local pmc by
+    by = get_hll_global 'infix:<=>'
+    $P0 = values.'min'(by)
+    .return ($P0)
+.end
+
+
+.namespace ['List']
+=item max()
+
+Return maximum element in list
+
+=cut
+
+.sub 'max' :method :multi('ResizablePMCArray')
+    .param pmc by              :optional
+    .param int has_by          :opt_flag
+    .local pmc elem, res, iter
+
+    if has_by goto start
+    by = get_hll_global 'infix:<=>'
+  start:
+    iter = self.'iterator'()
+    if iter goto do_work
+    res = new 'Failure'
+    goto done
+
+  do_work:
+    res = shift iter
+  loop:
+    unless iter goto done
+    elem = shift iter
+    $I0 = by(elem, res)
+    unless $I0 > 0 goto loop
+    res = elem
+    goto loop
+
+  done:
+    .return(res)
+.end
+
+.namespace []
+.sub 'max' :multi(Closure)
+    .param pmc by
+    .param pmc values          :slurpy
+    $P0 = values.'max'(by)
+    .return ($P0)
+.end
+
+.sub 'max' :multi()
+    .param pmc values          :slurpy
+    .local pmc by
+    by = get_hll_global 'infix:<=>'
+    $P0 = values.'max'(by)
+    .return ($P0)
+.end
+
+
 =back
 
 =head1 Functions

@p6rt
Copy link
Author

p6rt commented Jun 12, 2008

From @jnthn

Applied in r28259, thanks!

@p6rt
Copy link
Author

p6rt commented Jun 12, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 12, 2008

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Jun 12, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant