lua-users home
lua-l archive

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

On 4 September 2013 19:25, Ousmane Roland Yonaba
<> wrote:
> Since Lua 5.1, table.foreach and table.foreach were deprecated[1].
> It is known (I am such a fan of Game Of Thrones... :)).
> I would just like to know why. Are there good reasons to this ?
> I bet there are, as looking at the evolution of Lua, nothing is seems
> to be done without some solid motives at the basis.
> But to me, this syntax was so much beautiful:
>     table.foreach({...}, print)
> It misses me under Lua 5.2.x.
> Well, I am not saying I want it back. Just looking for...reasons.

This foreach function was present in Lua before the actual "for"
command was included, which amazingly was rather late in the
language's history (Lua 4.0 in 2000).

When they added "for", table.foreach became somewhat redundant,
because we had "for k,v in t", which produced similar funcionality.
Then that was removed too, replaced by the generator functions, so now
we have "for k,v in pairs(t)" and "for i,v in ipairs(t)". Then for a
while during work versions of Lua 5.2 the Lua authors even considered
getting rid of ipairs and making us use "for i=1,#t do" but
fortunately they retracted that change.

I for one miss "for k,v in t", as it is by far the most common
iteration pattern and IMHO deserved that special case (and there are
other places in the language where behavior changes if the value is a
function or a table anyway, such as __index in metatables and the repl
argument in string.gsub).

I'm not _saying_ I want it back, I appreciate the efforts for
orthogonality and minimalism... but I miss it. :)

-- Hisham