# New Ticket Created by Vasily Chekalkin
# Please include the string: [perl #55400]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=55400 >
Hello.
This is fix for reusing same range many times.
my $a = (1..5); say $a.from; my @b = $a; say 'One '[EMAIL PROTECTED]; say
$a.from; @b
= $a; say 'Two '[EMAIL PROTECTED];
Produces:
One 1 2 3 4 5
Two
Patch is partially useful even for (future) lazy lists.
--
Bacek.
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