lua-users home
lua-l archive

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


On Wed, Jul 24, 2013 at 3:34 PM, Thijs Schreijer
<thijs@thijsschreijer.nl> wrote:
> the missing love (from my part) is because the proposed isxxxxx() functions can be easily created on top of the most minimal required function to detect the difference of types.
>
> Having read most of it I think my preference would be a ˋsubtype()ˋ function, that would honor an ˋ__subtypeˋ metamethod (and, optionally, in absence of ˋ__subtypeˋ would return the name of a metatable).
>
> everything else can be easily built as an extension on top of this.
>
> Thijs

I see. Yes, it is trivial to make an adhoc isxxx function. What it
does provide is a clean what to accomplish what subtype accomplishes,
without leading to the inevitable, "what about subsubtype?"

Consider:

type.isnumber(2.1) --> true
type.isfloat(2.1) --> true
type.isinteger(2.1) -->false

Then later, in some Haskel-esque version of Lua:

type.isordinal(2.1) -->true

A function gives you more power than what equality to a string can.
Also, this keeps type related stuff inside of `type` and it doesn't
break:

type(2.1) --> "number"

That said, I like:

type(2.1, "float", "number") --> true

much better.

I'm going to steal that idea for my personal monkeypatched `type`,
which has to be *the* most abused standard library function in Lua.

-Andrew