lua-users home
lua-l archive

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


On Fri, Aug 15, 2014 at 1:16 PM, Jan Behrens <jbe-lua-l@public-software-group.org> wrote:
On Fri, 15 Aug 2014 13:37:41 -0300
Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
[...]
> If the goal is only to reduce calls to length, another option would be
> to modify ipairs so that it stops in the first nil entry with an index
> larger than #t. That would have some nice properties:
>[...]

It sounds like a "hack" to me.

It is very clever. I like it.
 
If we assume that nil's are allowed as values, then calling the length
operator here (even if it's just for a few nil elements) would require
the underlaying SQL library to iterate through all result rows to
return a length.

No, you simply need to return the current index + 1 to continue the loop.
 
e