[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: lua-l Digest, Vol 36, Issue 69
- From: "John Hind" <john.hind@...>
- Date: Wed, 24 Jul 2013 11:35:53 +0100
Rather than introduce a whole raft of predicates implemented in one of the
standard 'C' libraries, why not just extend type as suggested before:
type, subtype = type(x)
Which maintains compatibility except in very exotic cases, and ship an
additional optional library implemented in Lua which provides the
isinteger = function(x)
local t, s = type(x)
return (t == "number") and (s == "integer")
and so on for every desired type predicate ...
> Date: Wed, 24 Jul 2013 13:41:06 +0900
> From: Miles Bader <email@example.com>
> Subject: Re: Lua 5.3 work1 Considering math.isinteger or type()
> To: Thijs Schreijer <firstname.lastname@example.org>
> Cc: "email@example.com" <firstname.lastname@example.org>
> Message-ID: <email@example.com>
> Content-Type: text/plain
> Thijs Schreijer <firstname.lastname@example.org> writes:
> > Then I would rather have a single type() function and replace its
> > number' return value with the new types. Big incompatibility but the
> > new integer division operator already is. Incompatible but clean.
> Predicates are actually _more_ clean, and yet aren't incompatible
> ("isnumber" and "isinteger"/"isfloat" can exist simultaneously).
> If you are worried about function namespace pollution (I'm not,
> particularly, but ...), it's also possible to use a predicate-style
> solution with a separate type namespace, e.g. "istype(OBJ, TYPE)",
> where TYPE is 'number', 'float', 'table', etc.