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

Implementation of map for List #97

Closed
p6rt opened this issue May 23, 2008 · 17 comments
Closed

Implementation of map for List #97

p6rt opened this issue May 23, 2008 · 17 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 23, 2008

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

Searchable as RT54742$

@p6rt
Copy link
Author

p6rt commented May 23, 2008

From @bacek

Hello.

Reworked implementation of 'map'

--
Bacek

@p6rt
Copy link
Author

p6rt commented May 23, 2008

From @bacek

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

@p6rt
Copy link
Author

p6rt commented May 25, 2008

From @bacek

Reworked version which supports multiple arguments.

@p6rt
Copy link
Author

p6rt commented May 25, 2008

From @bacek

map.diff
Index: 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.

@p6rt
Copy link
Author

p6rt commented May 25, 2008

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

@p6rt
Copy link
Author

p6rt commented May 25, 2008

From @pmichaud

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

@p6rt
Copy link
Author

p6rt commented May 25, 2008

From @bacek

On Sat May 24 21​:27​:16 2008, pmichaud wrote​:

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.

Yes. Already updated to latest SVN and checked that without newclosure
everything works.

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

I'll made same changes for grep, reduce, etc.

May be we should also use Iterators instead of keyed access?

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.

My bad. Sorry. I''l remade patch.

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

Thanks!

Pm

--
Bacek.

@p6rt
Copy link
Author

p6rt commented May 26, 2008

From @bacek

On Sat May 24 21​:27​:16 2008, pmichaud wrote​:

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

New version attached.

--
Bacek

@p6rt
Copy link
Author

p6rt commented May 26, 2008

From @bacek

map.diff

@p6rt
Copy link
Author

p6rt commented May 26, 2008

From @bacek

On Sun May 25 18​:49​:39 2008, bacek wrote​:

New version attached.

And again. I found couple of bugs.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented May 26, 2008

From @bacek

map.diff
Index: 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.

@p6rt
Copy link
Author

p6rt commented May 26, 2008

From @bacek

On Sun May 25 18​:49​:39 2008, bacek wrote​:

New version attached.

And again. I found couple of bugs.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented May 26, 2008

From @bacek

map.diff
Index: 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.

@p6rt
Copy link
Author

p6rt commented May 27, 2008

From @bacek

On Mon May 26 06​:42​:13 2008, bacek wrote​:

On Sun May 25 18​:49​:39 2008, bacek wrote​:

New version attached.

And again. I found couple of bugs.

And again :) Previous was broken.

@p6rt
Copy link
Author

p6rt commented May 27, 2008

From @bacek

map.diff

@p6rt
Copy link
Author

p6rt commented May 28, 2008

From @pmichaud

Applied in r27877, thanks!

Pm

@p6rt
Copy link
Author

p6rt commented May 28, 2008

@pmichaud - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed May 28, 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