lua-users home
lua-l archive

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


On Mon, Mar 19, 2018 at 10:08 PM, Roberto Ierusalimschy wrote:
More concretely, I propose a little experiment: suppose that Lua raises
a run-time error for every assignment of nils to tables except in
explicit assignments with a constant nil (t[k]=nil). How frequently this
error will occurr without hinting a hidden bug in the code? (Please,
any answer should be about some piece of real, useful code where that
could happen.)


https://gist.github.com/Egor-Skriptunoff/1cf4070c7532db0f8ce0b875717801d8#file-integernumberinwords-lua-L33
Here a sequence of words is being created.
Depending on a parameter, an additional word must be inserted in the sequence:
"one hundred one" / "one hundred and one"
The following _expression_ is used:
   table.insert(array, parameter_which_may_be_nil and "word_to_be_inserted")
When parameter is nil, then nothing is inserted.  This is intended logic, not a hidden bug.