yodk icon indicating copy to clipboard operation
yodk copied to clipboard

Possible 'bool' type for NOLOL

Open Woccz opened this issue 3 years ago • 1 comments

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 when num type variables are used for logic, and when bool type variables are used for arithmetic.

This would mean code such as

Num x = 3
if x then ... end

would not be valid, however,

Num x = 3
if x != 0 then ... end

would be.

Any if x != 0 then ... end can still be compiled to if 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 that a or b cannot be optimised to a+b, as the programmer wants the 0 or 1 number value, as opposed to the boolean truthy value of a+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.

Woccz avatar Jun 15 '21 04:06 Woccz

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.

dbaumgarten avatar Jun 15 '21 18:06 dbaumgarten