lua-users home
lua-l archive

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


On Jul 24, 2013, at 3:35 AM, John Hind <john.hind@zen.co.uk> wrote:

> 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
> predicates:
> 
> isinteger = function(x)
>  local t, s = type(x)
>  return (t == "number") and (s == "integer")
> end
> 
> and so on for every desired type predicate ...
> 

Because there are subtle differences even in this case:

myfunction(type(x))

Suddenly gets an extra argument, which can break existing code. In addition, predicates are subtle when you have object models with various different inheritance rules and "isa" "hasa" issues.

--Tim