|
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 |