Open Woccz opened 3 years ago
Yes, there absolutely should be a bool-type. Wheter or not to allow arithmetics with bools remains to be decided. I am always for maximum type-safety. But in this case it could get annoying really fast. It's probably something to just try out and test how it feels.
In addition to #48.
Possibly add a
bool
type, used to differentiate truthy number variables from number variables used for arithmetic. This would allow for more optimisations in the future and could raise errors whennum
type variables are used for logic, and whenbool
type variables are used for arithmetic.This would mean code such as
would not be valid, however,
would be.
Any
if x != 0 then ... end
can still be compiled toif x then ... end
.Vise versa,
bool
type variables should not be allowed to be used for arithmetic, as the value in them is only defined by zero or non-zero.All comparisons and logical expressions should return a bool type.
This way, if the programmer wants to perform boolean arithmetic, for example,
x += a or b
, they will have to explicitly state this, i.e.x += (Num)(a or b)
. This will let the compiler know thata or b
cannot be optimised toa+b
, as the programmer wants the0
or1
number value, as opposed to the boolean truthy value ofa+b
.(Optionally,
bool
values could be used for arithmetic without casting or errors raised, and instead, detect arithmetic performed on bool values and eliminate any arithmatic optimisations used.)Thank you.