let name : String = "Alice";
if (name){ // Compilation error. Expected Boolean expression
printName(name);
}
To represent boolean values, Lense has the Boolean
type. Only two objects have type Boolean
: true
and false
.
Lense decision directives only allow Boolean
values and expressions as argument. For example, the following code will not compile:
let name : String = "Alice";
if (name){ // Compilation error. Expected Boolean expression
printName(name);
}
Operations upon booleans are divided in two categories Bitwise Operations and Logic Operations
Boolean
implements Injuctable
, Dijunctable
, ExclusiveDijunctable
in order to allow the use of the following bitwise operators:
& from Injuctable
: the bitwise AND operator
| from Dijunctable
: the bitwise OR operator
^ from ExclusiveDijunctable
: the bitwise XOR (Exclusive-OR) operator
These operators are commutative as the order of the operands is not relevant and both operands are evaluated.
These operators are not exclusive to type Boolean
, but when applied, these operators, regard Boolean
values as being equivalent to a single bit an operate bitwise according to they respective traditional Truth Tables.
Logic operators can only operate on Boolean
expressions. In Lense, logical operators are intrinsic and cannot be overloaded.
They are:
&& the logic AND operator
|| the logic OR operator
! the logic NOT operator
Logic operators &&
and ||
have short-circuit evaluation. The &&
operator evaluates the right side only if the left side is true
. The ||
operator evaluates the right side only if the left side is false
. These operators are not considered commutative because, even-thought the end logic result is the same, the side effects may not be. Since Lense is not a pure functional language side effects must be considered in the operators definition.
In most cases you will use Logic operators instead of Bitwise operators.
Boolean values are very common is method signatures so whenever possible the compiler will leverage the platforms native boolean type by means of erasure in order to perform better. Auto-boxing and auto-unboxing will be used when necessary to maintain consistency.