lua-users home
lua-l archive

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


On Mon, Oct 14, 2013 at 2:17 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2013/10/14 Andrew Starks <andrew.starks@trms.com>:
>
>> So, when I see `tostring(x)`, I expect that there is also `tonumber`
>> and `toboolean` and even `tonil` or totable, as nonsensical as the
>> last two might seem/be.
>
> 'tostring' is there so that humans can read its output. 'tonumber' is
> there because something else except a number can sometimes
> be converted to a number. 'totable' is not there because a table
> is a Swiss army knife, you don't know beforehand which blade
> to use.

To pull `tonumber` out as an example of my point:

tonumber is there, *except* as a metamethod. I maybe should have said,
"when I see `tostring` and the different ways in which it is used and
implemented..."

So, I see tostring(x) and then I see `__tostring = function(t) return
t.value end`, *as someone approaching the language*, I expect that
__tonumber is there and works in a similar way.

Often, Lua doesn't give me these tools, either because they're too
expensive or because including them would encourage stupid design.
This is fine. I'm only commenting on my reaction to the language and
some of the things that make me go "hmmmm..."

One could aggregate these assumed oversights-by-novices and write a
nice blog post... "So you think you need __tonumber/__gt/__ge?"

-Andrew