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
Fixed version of List.reduce with respect to arity. #120
Labels
Comments
From @bacekHello. Current version of List.reduce doesn't work anyway. -- |
From @bacekreduce.diffdiff --git a/languages/perl6/src/classes/List.pir b/languages/perl6/src/classes/List.pir
index 46eb4a8..23dd57f 100644
--- a/languages/perl6/src/classes/List.pir
+++ b/languages/perl6/src/classes/List.pir
@@ -479,20 +479,49 @@ Return a list of Pair(index, value) elements for the invocant.
.param pmc expression
.local pmc retv
.local pmc iter
- .local pmc block_res
- .local pmc block_arg
+ .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
- block_arg = shift iter
- block_res = expression(retv, block_arg)
+
+ # 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
|
From @bacekPatch was applied long time ago. |
@bacek - Status changed from 'new' to 'resolved' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Migrated from rt.perl.org#55368 (status was 'resolved')
Searchable as RT55368$
The text was updated successfully, but these errors were encountered: