lua-users home
lua-l archive

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


this will be easy to implement in pure lua, if you need a C interface, also easy implement in C. (with current Lua implement).

just use a empty table/function as empty value, and modify type function to return "empty" if called with this value.

table.has only check this empty value, and table.delete just put this empty value to place.

IMHO, what Tim want is just a "standard way" to something, in this topic, the "empty value" in array, but in facts, there are so many thing in Lua that indeed need a standard way. what about exception? what about OO?

the real question is, how to define a standard way, makes all Luaer works with it, but not affect the simply of Lua?

maybe we need something like lua manual, it's a standard, but not the Lua language, it's for the Lua usage, e.g. return nil, errmsg[, others] for error case, etc. and this empty value can put in this standard document.

or, some "std library", disturbed with Lua source, as a part of Lua language, but description of it is at other place (maybe it's the standard lua usage document).



2013/7/2 Roberto Ierusalimschy <roberto@inf.puc-rio.br>
> Couldn't a lot of ambiguity and unexpected behavior avoided by keeping
> nil but introducing two new functions to the table library called
> "table.has(t,key)" and "table.delete(t,key,[to])" - and dropping the
> deletion via assigning nil?

At last something new and worth a discussion. Does anyone see problems/
incompatibilities/etc. with this?

(But what is "[to]"?)

Keep in mind that #t would still be undefined for arrays with holes,
but holes would be much less frequent...

-- Roberto




--
regards,
Xavier Wang.