Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #113026] array iterator does not track a growing array

1 view
Skip to first unread message

Siddhant Saraf

unread,
May 21, 2012, 12:06:27 PM5/21/12
to bugs-bi...@rt.perl.org
# New Ticket Created by Siddhant Saraf
# Please include the string: [perl #113026]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=113026 >


$ perl6 -v
This is perl6 version 2012.05-15-gdca0fa6 built on parrot 4.4.0
revision RELEASE_4_4_0

<sisar> so here is the same code in perl6 and python:
https://gist.github.com/2762953. While the perl6 the loop terminates,
in pyhton it is an infinite loop. Though both behaviour have their
reasons, I can't decide which is better.
<sisar> why python's behaviour is logical, perl6's behaviour is trying
to prevent one from potentially infinite loops
...
<sisar> so, perl6 makes a temporary copy of @array before it even
starts looping. Why ?
...
<flussence> it counts the array then iterates over it
...
<flussence> copying every array just to loop over it would be crazy
inefficient, I think only PHP does that (and only because it uses copy
on write)
<sisar> flussence: what are merits of that, counting before iterating ?
<sisar> flussence: aye, making a copy would be super inefficient.
<flussence> if you have an SQL result pretending to be an array, you
don't want it going off and calling a .count that does "select
count(*)" on every iteration
<sisar> flussence: i'm sorry i'm not familiar with SQL
<geekosaur> don't worry about it. point is that an array might not be
an array, it might be a big chunk of code pretending to be an array
<geekosaur> and you don't want to hammer that big chunk of code pointlessly
<flussence> it'd be like calling strlen() in C on a really big string
...
<TimToady> the whole point of lazy lists is that you never ask for the
size of something you're iterating over if you can help it
<TimToady> and I think an array iterator should be able to track a
growing array without snapshotting the old length
<flussence> that makes sense, but I can't imagine it being fun to implement :)
...
<sisar> TimToady: so it is a genuine bug? fwiw, both niecza and rakudo
iterate only twice.
<TimToady> I think so

Patrick R. Michaud via RT

unread,
May 21, 2012, 2:15:07 PM5/21/12
to perl6-c...@perl.org
I suspect this bug may be related to #112716
(https://rt.perl.org/rt3/Ticket/Display.html?id=112716); the .map()
operation (which 'for' uses) tends to be a bit too eager in evaluating
its invocant list.

I've taken both bugs and will work on a fix shortly.

Pm

Will Coleda via RT

unread,
Aug 29, 2015, 5:45:03 AM8/29/15
to perl6-c...@perl.org
On Mon May 21 11:45:12 2012, KyleHa wrote:
> I put a test for this in S04-statements/for.t

Which is now passing in the glr branch. Closing ticket.
--
Will "Coke" Coleda
0 new messages