lua-users home
lua-l archive

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


On Dec 6, 2012, at 6:56 PM, Wolfgang Pupp wrote:

> - pairs needs to be a "magical" function anyway (can't be implemented
> without "cheating"),

It's not magic; next() is. http://www.lua.org/pil/7.3.html

> and it basically *never* appears outside of the
> for-statement (it is never needed "as function"- only for what it
> achieves inside a for-loop).

The same is true of string.gfind() and io.lines() of course.

The Lua iterator protocol is very nice. 5.0 pairs() vs ipairs() forces you to state intent. But yeah, the novelty value of typing "pairs()" over and over again is wearing off.

There are a couple of decent Lua parsers out there. It might be fun to do a survey of some large Lua corpus to find the relative frequency of pairs and ipairs versus other uses of the generic for.