lua-users home
lua-l archive

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


On Wed, Dec 10, 2014 at 8:52 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2014-12-10 16:44 GMT+02:00 Rena <hyperhacker@gmail.com>:
>
>> Interesting. Why is __tostring not a core metamethod? The distinction
>> seems arbitrary to me.
>
> A core metamethod is a fallback. It is called when Lua does not
> know what to do, as a last resort instead of throwing an error.
> __tostring, __pairs etc are called _instead_ of what Lua knows
> to do.
>

I don't make that distinction, even when I'm reminded that the authors do.

The reason is that, to me, it's meaningless. It works or it does not
work and remembering where it works and doesn't is not something that
I care to invest the time to memorize. At best, I know that whenever I
define `__ipairs`... sort of worry that it may not work, if my table
is handed to a library that may not honor it. To my way of thinking,
there are fields that are attached to metatables that begin with `__`
and end with the name of the method that they modify. Anything beyond
this, to paraphrase the Bible, is complex.

I don't know if this is important enough to bring up in another
thread, but I also don't like the deprecation of `__ipairs`. Whatever
the redundancy it may suffer, it is clear to the writer or reader of
the code that a sequence of key/value pairs, iterated in a consistent
order, is expected. If `ipairs` and `pairs` exist and we allow for a
way to override `pairs`, then consistency would require a
corresponding way to override ipairs.

I may be misunderstanding this issue and I may be mistaken about 5.3
deprecating it. If I am correct, then it appears to me that the
evolution of Lua is such that  eradicating redundancy is valued over
consistency. "Consistency" can be argued about (see math library
change).

I guess any person's definition of "simplicity" is their own.

-Andrew