develooper Front page | perl.perl5.porters | Postings from March 2013

Re: Infinite loop in for (@a) { push @a, $_ }

Thread Previous | Thread Next
From:
ilmari
Date:
March 19, 2013 12:08
Subject:
Re: Infinite loop in for (@a) { push @a, $_ }
Message ID:
d8jy5djr3s3.fsf@dalvik.ping.uio.no
demerphq <demerphq@gmail.com> writes:

> On 19 March 2013 12:43, Nicholas Clark <nick@ccl4.org> wrote:
>
>>> Does anyone agree? I would expect this to be the same (more or less) as:
>>>
>>> push @a, @a;
>>>
>>> And not an infinite loop.
>>
>> I'd like it not to be an infinite loop, but I'm not sure what the cost of
>> fixing it would be. If I understand this one correctly, it's not actually
>> a "stack isn't reference counted" bug. It's an optimisation peeping through.
>
> Seems to me we just* have to remember the size of the array when we
> start the for() loop and only iterate to that size. That would
> preserve the behavior of 5.001.

But change the behaviour of every version since for cases that only push
a finite number if items onto the array and expect them to be iterated
over.

-- 
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
 the consequences of."                              -- Skud's Meta-Law


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About