On 13/07/2017 14:54, Nathaniel Musgrove wrote:
On Thu, Jul 13, 2017 at 5:47 AM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
Allowing t to be omitted is confusing because it is in the interest of
the programmer to be explicit about what metatable is being set.
setmetatable(v) is not explicit and seems very confusing to me.
There are exactly zero other scenarios in Lua where f(nil) produces
different
behavior than f(). The fact that this function is the sole exception
to the
rule violates the principle of least astonishment.
If the programmer wishes to use an explicit nil, that should be their
choice,
not an arbitrary requirement that exists nowhere else.
Regards,
Nathaniel
I don't agree, sorry.
Usually when you omit an argument and that argument it's interpreted as
nil it is a strong hint that that argument is intended to be optional
and some *senisble* default is to be used.
in setmetatable the t argument is not at all optional, semantically, it
is the very "target" of the operation. It would be very confusing to be
able to omit an argument just as a shortcut for `nil`, when you just
want to change the metatable of `nil`. This goes *against* the principle
of least astonishment, IMO: if I'm setting a new metatable (something
very low level and "risky"), I like to be explicit. What's the point of
having t default to "nil". Note that here `nil` doesn't mean "no
argument", but it means `nil` really, i.e. the type `nil` whose only
value is `nil`.
cheers!
-- Lorenzo