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 map for List #97
Comments
From @bacekHello. Reworked implementation of 'map' -- |
From @bacekmap.diffIndex: src/classes/List.pir
===================================================================
--- src/classes/List.pir (revision 27774)
+++ src/classes/List.pir (working copy)
@@ -709,6 +709,31 @@
.return 'list'(arr)
.end
+=item map()
+
+Map.
+
+=cut
+
+.sub 'map' :method
+ .param pmc expression
+ .local pmc res, elem, block, mapres, iter
+
+ res = new 'List'
+ iter = new 'Iterator', self
+ loop:
+ unless iter goto done
+ elem = shift iter
+ newclosure block, expression
+ mapres = block(elem)
+
+ res.'push'(mapres)
+ goto loop
+
+ done:
+ .return(res)
+.end
+
=back
=head1 Functions
@@ -768,6 +793,20 @@
.end
+=item C<map>
+
+Operator form of C<map>. Delegates map to passed list.
+
+=cut
+
+.sub 'map' :multi(_,List)
+ .param pmc expression
+ .param pmc list
+
+ .return list.'map'(expression)
+.end
+
+
=item C<infix:,(...)>
Operator form for building a list from its arguments.
@@ -1118,8 +1157,9 @@
.return list.'uniq'()
.end
-## TODO: join map reduce sort zip
+## TODO: zip
+
=back
=cut
|
From @bacekReworked version which supports multiple arguments. |
From @bacekmap.diffIndex: src/classes/List.pir
===================================================================
--- src/classes/List.pir (revision 27780)
+++ src/classes/List.pir (working copy)
@@ -709,6 +709,55 @@
.return 'list'(arr)
.end
+=item map()
+
+Map.
+
+=cut
+
+.sub 'map' :method
+ .param pmc expression
+ .local pmc res, elem, block, mapres, iter, args
+ .local int i, arity
+
+ arity = expression.'arity'()
+
+ res = new 'List'
+ iter = new 'Iterator', self
+ loop:
+ unless iter goto done
+
+ # Creates arguments for closure
+ args = new 'ResizablePMCArray'
+
+ i = 0
+ args_loop:
+ if i == arity goto invoke
+ unless iter goto create_undef
+
+ elem = shift iter
+ if elem goto push_elem
+ create_undef:
+ elem = new 'Undef'
+
+ push_elem:
+ push args, elem
+ inc i
+ goto args_loop
+
+ invoke:
+ newclosure block, expression
+ mapres = block(args :flat)
+
+ res.'push'(mapres)
+ goto loop
+
+ done:
+ .return(res)
+.end
+
+
+
=back
=head1 Functions
@@ -768,6 +817,20 @@
.end
+=item C<map>
+
+Operator form of C<map>. Delegates map to passed list.
+
+=cut
+
+.sub 'map' :multi(_,List)
+ .param pmc expression
+ .param pmc list
+
+ .return list.'map'(expression)
+.end
+
+
=item C<infix:,(...)>
Operator form for building a list from its arguments.
|
@bacek - Status changed from 'new' to 'open' |
From @pmichaudOn Fri, May 23, 2008 at 03:28:32PM -0700, Vasily Chekalkin wrote:
Excellent. A couple of notes: 1. Calling 'newclosure' from within 'map' is almost certainly wrong. I notice that 'grep' is also calling 'newclosure', and we probably 2. The patch file has quite a few tab characters and trailing spaces If you can resubmit the patch to address the above items, I Thanks! Pm |
From @bacekOn Sat May 24 21:27:16 2008, pmichaud wrote:
Yes. Already updated to latest SVN and checked that without newclosure
I'll made same changes for grep, reduce, etc. May be we should also use Iterators instead of keyed access?
My bad. Sorry. I''l remade patch.
-- |
From @bacekOn Sat May 24 21:27:16 2008, pmichaud wrote:
New version attached. -- |
From @bacekOn Sun May 25 18:49:39 2008, bacek wrote:
And again. I found couple of bugs. -- |
From @bacekmap.diffIndex: src/classes/List.pir
===================================================================
--- src/classes/List.pir (revision 27812)
+++ src/classes/List.pir (working copy)
@@ -709,6 +706,60 @@
.return 'list'(arr)
.end
+=item map()
+
+Map.
+
+=cut
+
+.sub 'map' :method
+ .param pmc expression
+ .local pmc res, elem, block, mapres, iter, args
+ .local int i, arity
+
+ arity = expression.'arity'()
+ if arity > 0 goto body
+ arity = 1
+
+ body:
+ res = new 'List'
+ iter = new 'Iterator', self
+ loop:
+ unless iter goto done
+
+ # Creates arguments for closure
+ args = new 'ResizablePMCArray'
+
+ i = 0
+ args_loop:
+ if i == arity goto invoke
+ unless iter goto create_undef
+
+ elem = shift iter
+ if elem goto push_elem
+ create_undef:
+ elem = new 'Undef'
+
+ push_elem:
+ push args, elem
+ inc i
+ goto args_loop
+
+ invoke:
+ mapres = expression(args :flat)
+ if null mapres goto loop
+
+ push_res:
+ res.'push'(mapres)
+ goto loop
+
+ done:
+ .return(res)
+.end
+
+
+
=back
=head1 Functions
@@ -768,6 +819,20 @@
.end
+=item C<map>
+
+Operator form of C<map>. Delegates map to passed list.
+
+=cut
+
+.sub 'map' :multi(_,List)
+ .param pmc expression
+ .param pmc list
+
+ .return list.'map'(expression)
+.end
+
+
=item C<infix:,(...)>
Operator form for building a list from its arguments.
|
From @bacekOn Sun May 25 18:49:39 2008, bacek wrote:
And again. I found couple of bugs. -- |
From @bacekmap.diffIndex: src/classes/List.pir
===================================================================
--- src/classes/List.pir (revision 27812)
+++ src/classes/List.pir (working copy)
@@ -709,6 +706,60 @@
.return 'list'(arr)
.end
+=item map()
+
+Map.
+
+=cut
+
+.sub 'map' :method
+ .param pmc expression
+ .local pmc res, elem, block, mapres, iter, args
+ .local int i, arity
+
+ arity = expression.'arity'()
+ if arity > 0 goto body
+ arity = 1
+
+ body:
+ res = new 'List'
+ iter = new 'Iterator', self
+ loop:
+ unless iter goto done
+
+ # Creates arguments for closure
+ args = new 'ResizablePMCArray'
+
+ i = 0
+ args_loop:
+ if i == arity goto invoke
+ unless iter goto create_undef
+
+ elem = shift iter
+ if elem goto push_elem
+ create_undef:
+ elem = new 'Undef'
+
+ push_elem:
+ push args, elem
+ inc i
+ goto args_loop
+
+ invoke:
+ mapres = expression(args :flat)
+ if null mapres goto loop
+
+ push_res:
+ res.'push'(mapres)
+ goto loop
+
+ done:
+ .return(res)
+.end
+
+
+
=back
=head1 Functions
@@ -768,6 +819,20 @@
.end
+=item C<map>
+
+Operator form of C<map>. Delegates map to passed list.
+
+=cut
+
+.sub 'map' :multi(_,List)
+ .param pmc expression
+ .param pmc list
+
+ .return list.'map'(expression)
+.end
+
+
=item C<infix:,(...)>
Operator form for building a list from its arguments.
|
From @bacekOn Mon May 26 06:42:13 2008, bacek wrote:
And again :) Previous was broken. |
From @pmichaudApplied in r27877, thanks! Pm |
@pmichaud - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#54742 (status was 'resolved')
Searchable as RT54742$
The text was updated successfully, but these errors were encountered: