lua-users home
lua-l archive

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



On Jan 9, 2015, at 12:44 PM, Enrique Arizón Benito <enrique.arizonbenito@gmail.com> wrote:

Hi,

The idea is to remove from the syntax and from the virtual machine. Since nil doesn't exists, mathematically it's not possible to have nil errors. nil must be replaced, but are replaced with default sensible (from the program point of view) values. Looks strange but it's always possible to replace a nil with a default value. Actually the program is always trying to solve an algorithm and nil, being and undefined variable that can not even be read (just compared), will not help at all to solve the problem. Some algorithms can not have a solution for a given set of input values (for example searching the value of a non-existing key in an array). In such case exceptions are raised. It's the way the code has to indicate "Sorry, I can't continue since I don't know what to do next".

Regards,

Enrique


nil in Lua really has nothing to do with NULL in C. Although nil is somewhat overloaded in Lua, one common usage is as an out-of-band sentinel value. You state that “it is always possible to replace a nil with a default value”, but what would that value be? Sentinel values cannot be in-band, as they are then ambiguous (indistinguishable from a valid in-band value). So you either have to have magical kinda-sorta out-of-band values that are hacked (like -1 for EOF in C APIs) or you need a value that is out-of-band because it’s specific purpose is just that .. in other words .. nil!

And nil is NOT “an undefined variable that cannot even be read” .. it’s a perfectly respectable literal value which happens to be the only value of the nil type. I think you will find if you try to remove nil you will end up with a language that is far less concise and elegant.

—Tim