lua-users home
lua-l archive

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


On Wednesday 29 December 2010 01:30:11 Juris Kalnins wrote:
> On Tue, 28 Dec 2010 21:45:04 +0200, Richard Hundt <richardhundt@gmail.com>
> 
> wrote:
> > Is there something inherently Bad about doing this?
> >
> > for k,v in next, t, #t > 0 and #t or nil do
> >     ...
> > end
> 
> yes.
> 
> ipairs stop at the first 'nil', and this code loses
> all values from there to the '#t'.

Also, even if there were no nils, if somehow the ones with the string or 
fractional keys came up BEFORE the integer ones, those string and fractional 
keys wouldn't be processed.

For instance, if next or pairs brought them up like shown in the following 
list of keys:

"early"
1.33
1
2
3
1.5
"late"

then the suggested algorithm would show 1.5 and "late", but would miss "early" 
and 1.33.

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt