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

Move first/reduce methods and subs into the Any class #512

Closed
p6rt opened this issue Dec 20, 2008 · 6 comments
Closed

Move first/reduce methods and subs into the Any class #512

p6rt opened this issue Dec 20, 2008 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 20, 2008

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

Searchable as RT61560$

@p6rt
Copy link
Author

p6rt commented Dec 20, 2008

From @cspencer

The first and reduce methods/subroutines were moved into the Any class to
make them available to Ranges as well as Lists.

The were unavailable to Ranges previously, throwing a fatal error.

@p6rt
Copy link
Author

p6rt commented Dec 20, 2008

From @cspencer

any-first-reduce.patch
Index: src/builtins/any-list.pir
===================================================================
--- src/builtins/any-list.pir	(revision 34158)
+++ src/builtins/any-list.pir	(working copy)
@@ -55,6 +55,45 @@
     .return ($I0)
 .end
 
+=item first(...)
+
+=cut
+
+.namespace []
+.sub 'first' :multi('Sub')
+    .param pmc test
+    .param pmc values :slurpy
+
+    .tailcall values.'first'(test)
+.end
+
+.namespace ['Any']
+.sub 'first' :method :multi(_, 'Sub')
+    .param pmc test
+    .local pmc retv
+    .local pmc iter
+    .local pmc block_res
+    .local pmc block_arg
+
+    iter = self.'iterator'()
+  loop:
+    unless iter goto nomatch
+    block_arg = shift iter
+    block_res = test(block_arg)
+    if block_res goto matched
+    goto loop
+
+  matched:
+    retv = block_arg
+    goto done
+
+  nomatch:
+    retv = '!FAIL'('Undefined value - first list match of no matches')
+
+  done:
+    .return(retv)
+.end
+
 =item grep(...)
 
 =cut
@@ -340,7 +379,69 @@
     .tailcall self.'pick'($I0)
 .end
 
+=item reduce(...)
 
+=cut
+
+.namespace []
+.sub 'reduce' :multi('Sub')
+    .param pmc expression
+    .param pmc values          :slurpy
+    .tailcall values.'reduce'(expression)
+.end
+
+.namespace ['Any']
+.sub 'reduce' :method :multi(_, 'Sub')
+    .param pmc expression
+    .local pmc retv
+    .local pmc iter
+    .local pmc elem
+    .local pmc args
+    .local int i, arity
+
+    arity = expression.'arity'()
+    if arity < 2 goto error
+
+    iter = self.'iterator'()
+    unless iter goto empty
+    retv = shift iter
+  loop:
+    unless iter goto done
+
+    # Create arguments for closure
+    args = new 'ResizablePMCArray'
+    # Start with 1. First argument is result of previous call
+    i = 1
+
+  args_loop:
+    if i == arity goto invoke
+    unless iter goto elem_undef
+    elem = shift iter
+    goto push_elem
+  elem_undef:
+    elem = new 'Failure'
+
+  push_elem:
+    push args, elem
+    inc i
+    goto args_loop
+
+  invoke:
+    retv = expression(retv, args :flat)
+    goto loop
+
+  empty:
+    retv = new 'Undef'
+    goto done
+
+  error:
+    'die'('Cannot reduce() using a unary or nullary function.')
+    goto done
+
+  done:
+    .return(retv)
+.end
+
 =item reverse()
 
 =cut
Index: src/classes/List.pir
===================================================================
--- src/classes/List.pir	(revision 34158)
+++ src/classes/List.pir	(working copy)
@@ -16,7 +16,7 @@
     p6meta.'register'('ResizablePMCArray', 'parent'=>listproto, 'protoobject'=>listproto)
 
     $P0 = get_hll_namespace ['List']
-    '!EXPORT'('first,keys,kv,pairs,reduce,values', $P0)
+    '!EXPORT'('keys,kv,pairs,values', $P0)
 .end
 
 =head2 Methods
@@ -297,45 +297,6 @@
 .end
 
 
-
-=item first(...)
-
-=cut
-
-.sub 'first' :method :multi('ResizablePMCArray', 'Sub')
-    .param pmc test
-    .local pmc retv
-    .local pmc iter
-    .local pmc block_res
-    .local pmc block_arg
-
-    iter = self.'iterator'()
-  loop:
-    unless iter goto nomatch
-    block_arg = shift iter
-    block_res = test(block_arg)
-    if block_res goto matched
-    goto loop
-
-  matched:
-    retv = block_arg
-    goto done
-
-  nomatch:
-    retv = '!FAIL'('Undefined value - first list match of no matches')
-
-  done:
-    .return(retv)
-.end
-
-
-.sub 'first' :multi('Sub')
-    .param pmc test
-    .param pmc values :slurpy
-
-    .tailcall values.'first'(test)
-.end
-
 =item fmt
 
  our Str multi List::fmt ( Str $format, $separator = ' ' )
@@ -465,69 +426,6 @@
     .tailcall values.'pairs'()
 .end
 
-
-=item reduce(...)
-
-=cut
-
-.sub 'reduce' :method :multi('ResizablePMCArray', 'Sub')
-    .param pmc expression
-    .local pmc retv
-    .local pmc iter
-    .local pmc elem
-    .local pmc args
-    .local int i, arity
-
-    arity = expression.'arity'()
-    if arity < 2 goto error
-
-    iter = self.'iterator'()
-    unless iter goto empty
-    retv = shift iter
-  loop:
-    unless iter goto done
-
-    # Create arguments for closure
-    args = new 'ResizablePMCArray'
-    # Start with 1. First argument is result of previous call
-    i = 1
-
-  args_loop:
-    if i == arity goto invoke
-    unless iter goto elem_undef
-    elem = shift iter
-    goto push_elem
-  elem_undef:
-    elem = new 'Failure'
-
-  push_elem:
-    push args, elem
-    inc i
-    goto args_loop
-
-  invoke:
-    retv = expression(retv, args :flat)
-    goto loop
-
-  empty:
-    retv = new 'Undef'
-    goto done
-
-  error:
-    'die'('Cannot reduce() using a unary or nullary function.')
-    goto done
-
-  done:
-    .return(retv)
-.end
-
-.sub 'reduce' :multi('Sub')
-    .param pmc expression
-    .param pmc values          :slurpy
-    .tailcall values.'reduce'(expression)
-.end
-
-
 =item uniq(...)
 
 =cut

@p6rt
Copy link
Author

p6rt commented Dec 20, 2008

From @pmichaud

Patch applied in r34162.

Assigning ticket to moritz++; we can close the ticket when we have
confirmation of tests for this feature.

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Dec 20, 2008

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

@p6rt
Copy link
Author

p6rt commented Dec 22, 2008

From @moritz

On Sat Dec 20 12​:40​:21 2008, pmichaud wrote​:

Patch applied in r34162.

Assigning ticket to moritz++; we can close the ticket when we have
confirmation of tests for this feature.

Sending t/spec/S03-operators/range.t
Transmitting file data .
Committed revision 24555.

There you go.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Dec 22, 2008

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

@p6rt p6rt closed this as completed Dec 22, 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