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

Fix Range reusing. #121

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

Fix Range reusing. #121

p6rt opened this issue Jun 6, 2008 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Jun 6, 2008

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

Searchable as RT55400$

@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

From @bacek

Hello.

This is fix for reusing same range many times.

my $a = (1..5); say $a.from; my @​b = $a; say 'One '@​b; say $a.from; @​b
= $a; say 'Two '
@​b;

Produces​:
One 1 2 3 4 5
Two

Patch is partially useful even for (future) lazy lists.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

From @bacek

Inline Patch
diff --git a/languages/perl6/src/classes/Range.pir b/languages/perl6/src/classes/Range.pir
index ecd24ca..f0670ee 100644
--- a/languages/perl6/src/classes/Range.pir
+++ b/languages/perl6/src/classes/Range.pir
@@ -53,11 +53,12 @@ we need to not do that.
 =cut
 
 .sub 'list' :method
-    .local pmc res, cur_val
+    .local pmc res, cur_val, it
+    it = iter self
     res = new 'List'
   it_loop:
-    unless self goto it_loop_end
-    cur_val = shift self
+    unless it goto it_loop_end
+    cur_val = shift it
     push res, cur_val
     goto it_loop
   it_loop_end:
@@ -114,12 +115,18 @@ Returns a Perl code representation of the range.
 
 =item get_iter (vtable)
 
-Just returns this Range itself, since a Range is an iterator.
+Clone this Range itself, since a Range is an iterator.
 
 =cut
 
 .sub get_iter :method :vtable
-    .return (self)
+    .local pmc from, to, retv
+    $P0 = self.'from'()
+    from = clone $P0
+    $P0 = self.'to'()
+    to = clone $P0
+    retv = 'infix:..'(from, to)
+    .return(retv)
 .end
 
 

@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

From @bacek

On Fri Jun 06 01​:07​:56 2008, bacek wrote​:

Hello.

New version of fix after jonathan comments.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

From @bacek

range2.diff

@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

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

@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

From @pmichaud

Applied (with minor mods) in r28129.

Thanks!

Pm

1 similar comment
@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

From @pmichaud

Applied (with minor mods) in r28129.

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Jun 6, 2008

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

@p6rt p6rt closed this as completed Jun 6, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant