lua-users home
lua-l archive

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


Edgar Toernig writes:

>> (http://lua-users.org/wiki/BooleanTypeProposal) I had a slight question/concern with the following -
 -- Relational operators return false for false and a value other than
 -- false/nil for true

In fact, they always return the number 1 for true.  Maybe it's better
to say that explicitely (and define true to be 1). That way (a==b) == (c==d) and alike becomes valid.

I would prefer that this explicitly evaluated to a distinct 'true'
type - if there is no explicit 'true' value it is impossible to
correctly serialise the value for an API which expects a destinct
boolean value (in this case specifically XMLRPC but generally true) by
checking the type.
eg. { aaa = true|false } will be serialised as a boolean if false
(as this is a distinct type) but as an integer if true & true is
represented as "1".
This could be fixed by explicity casting to a user type but this is
somewhat ugly.

And then define that if/while/not/... only accept 'false' and 'true'?
I thought about it myself but IMHO it complicates things more than
it would help.

I dont think that this is necessary - all non nil/false values can
still be treated as true - this is just a specialisation of the
inplementation to include a 'true' class which is returned by
relational operators (and can be explicitly assigned) - I dont think
that this changes the semantics at all just makes it easier to detect
boolean values for code that requires this (relational opeartors still
return a non-nil value as per the current implementation - this non-nil
value just happens to have a type of 'true') Regards, PaulC