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
Comments
From @cspencerThe first and reduce methods/subroutines were moved into the Any class to The were unavailable to Ranges previously, throwing a fatal error. |
From @cspencerany-first-reduce.patchIndex: 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
|
From @pmichaudPatch applied in r34162. Assigning ticket to moritz++; we can close the ticket when we have Thanks! Pm |
The RT System itself - Status changed from 'new' to 'open' |
From @moritzOn Sat Dec 20 12:40:21 2008, pmichaud wrote:
Sending t/spec/S03-operators/range.t There you go. Cheers, |
@moritz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#61560 (status was 'resolved')
Searchable as RT61560$
The text was updated successfully, but these errors were encountered: