[perl #54742] [PATCH] Implementation of map for List

2008-05-24 Thread via RT
# New Ticket Created by  Vasily Chekalkin 
# Please include the string:  [perl #54742]
# in the subject line of all future correspondence about this issue. 
# URL: http://rt.perl.org/rt3/Ticket/Display.html?id=54742 


Hello.

Reworked implementation of 'map'

-- 
Bacek
Index: 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 Cmap
+
+Operator form of Cmap. Delegates map to passed list.
+
+=cut
+
+.sub 'map' :multi(_,List)
+.param pmc expression 
+.param pmc list
+
+.return list.'map'(expression)
+.end
+
+
 =item Cinfix:,(...)
 
 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


Re: [perl #54742] [PATCH] Implementation of map for List

2008-05-24 Thread Patrick R. Michaud
On Fri, May 23, 2008 at 03:28:32PM -0700, Vasily Chekalkin wrote:
 Hello.
 
 Reworked implementation of 'map'

Excellent.  A couple of notes:

1.  Calling 'newclosure' from within 'map' is almost certainly wrong.
The newclosure op can only be called for closures that have the
current sub set as their ':outer', and that will never be the
case here.  Until tonight PCT had some issues with generating
newclosures at the right points, but I think that's now resolved.

I notice that 'grep' is also calling 'newclosure', and we probably
need to eliminate it there as well.

2.  The patch file has quite a few tab characters and trailing spaces
in it, which causes some of Parrot's codingstd tests to fail.

If you can resubmit the patch to address the above items, I
(or someone else) can quickly apply it.

Thanks!

Pm