lua-users home
lua-l archive

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


Many thanks for the examples. All of them actually would raise errors in
my little experiment, but let us see them in the discussion about nils
in tables.

The example from Tomás, about optional parameters to functions with
named arguments, is fully compatible with nils in tables. (It is really
adding a nil to a table, just it makes no difference that the nil is not
there.)

In the examples from Hisham, I could not figure out whether we should see
the nils as actual values or "instructions" to not add something.
For instance, in the case of

  entity[k] = default_value(field)

does a nil mean no default or a nil as the default? Would it make any
difference to the program if the nil was added to the table?

The example from Javier, however, clearly uses a nil as an "instruction"
not to add something. So, it is directly incompatible with the nils in
tables idea.

The example from Egor let me wondering why not to write

  if parameter_which_may_be_nil then
     table.insert(array, "word_to_be_inserted")
  end

instead of

     table.insert(array, parameter_which_may_be_nil and "word_to_be_inserted")

It is clearer (in my view) and faster; ok, I grant the original uses less
characters :-). Anyway, it is another valid example that is directly
incompatible with the nils in tables idea.

-- Roberto