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

Fixed version of List.reduce with respect to arity. #120

Closed
p6rt opened this issue Jun 6, 2008 · 4 comments
Closed

Fixed version of List.reduce with respect to arity. #120

p6rt opened this issue Jun 6, 2008 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 6, 2008

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

Searchable as RT55368$

@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

From @bacek

Hello.

Current version of List.reduce doesn't work anyway.

--
Bacek

@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

From @bacek

reduce.diff
diff --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

@p6rt
Copy link
Author

p6rt commented Nov 13, 2008

From @bacek

Patch was applied long time ago.

@p6rt
Copy link
Author

p6rt commented Nov 13, 2008

@bacek - Status changed from 'new' to 'resolved'

@p6rt p6rt closed this as completed Nov 13, 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