lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Roberto Ierusalimschy <roberto@inf.puc-rio.br> writes:

>> On Tue, May 18, 2010 at 8:12 PM, Petite Abeille
>> <petite.abeille@gmail.com> wrote:
>> > Hmmm... ipairs? deprecated? ouch.
>> 
>> Wow, yeah. Pretty bold. I notice that the readme still refers to it:
>> "ipairs now goes until #t" (i.e. respecting __len metamethods) - and
>> that change (as far as I understand it) must have meant either
>> changing what ipairs returns into a closure, or else calculating #t
>> every iteration - both of which would have been a bit costlier than
>> what the old one did.
>
> Not really. It only needs to calculate #t when the value is nil.
>
>> So I can see why it would have been recommended to move to using
>> numeric loop instead.
>
> The point is that it does exactly the same that a numeric loop, so
> there was no point in keeping it.

If both do exactly the same, the logical thing to keep would be ipairs,
not the numeric loop.  Simplifies the language.  _And_ you can pass
ipairs around, as a function argument, as a data structure element,
whenever the receiver needs any old iterator.  You can't pass a "numeric
loop" around other than wrapping it into a closure.

-- 
David Kastrup