# New Ticket Created by  Vasily Chekalkin 
# Please include the string:  [perl #54642]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=54642 >


Hello

There is attached initial implementation of map.

-- 
Bacek.
Index: src/classes/List.pir
===================================================================
--- src/classes/List.pir	(revision 27739)
+++ src/classes/List.pir	(working copy)
@@ -670,6 +670,39 @@
     .return 'list'(arr)
 .end
 
+=item map()
+
+Map.
+
+=cut
+
+.sub 'map' :method
+    .param pmc expression
+    .local pmc res, elem, mapres, newitem
+    .local int len, i
+
+    res = new 'List'
+    len = elements self
+    i = 0
+  loop:
+    if i == len goto done
+    elem = self[i]
+    inc i
+    mapres = expression(elem)
+
+    # flatten mapres
+    mapres = 'list'(mapres) 
+  copy_loop:
+    unless mapres goto loop
+    newitem = shift mapres
+    res.'push'(newitem)
+    goto copy_loop
+
+
+  done:
+
+    .return(res)
+.end
 =back
 
 =head1 Functions
@@ -729,6 +762,22 @@
 .end
 
 
+=item C<map>
+
+Operator form of C<map>. Creates List and delegates map to it.
+
+=cut
+
+.sub 'map'
+    .param pmc expression 
+    .param pmc args :slurpy
+    .local pmc l
+
+    l = 'list'(args :flat)
+    .return l.'map'(expression)
+.end
+
+
 =item C<infix:,(...)>
 
 Operator form for building a list from its arguments.
@@ -1079,8 +1128,9 @@
     .return list.'uniq'()
 .end
 
-## TODO: join map reduce sort zip
 
+## TODO: map zip
+
 =back
 
 =cut
@@ -1090,3 +1140,4 @@
 #   fill-column: 100
 # End:
 # vim: expandtab shiftwidth=4 ft=pir:
+

Reply via email to