Open FranciscoJavierPizarro opened 4 months ago
Boolean will likely not be added as the native operations, since you can just use integers for that, but as builtin data types like List
and String
are.
That way, we can also do lazy evaluation of nested conditions and short-circuiting like you said
Currently, the boolean data type is not defined by default; you must define it yourself (see examples/all_tree.bend).
At present, if you perform a comparison like
0 == 0
, it returns1
.The boolean values should be like those in Python:
True
andFalse
. The standard operators can also be like those in Python:not
,and
,or
.Another additional feature you can add is the shortcut version of the operators. To provide different syntax options, you can use the usual C++ syntax:
||
and&&
. The difference between the two types should be that the first ones (Python-style) evaluate all conditions, while the second ones (C++-style) follow the original order and stop as soon as the result is determined. For example, inTrue || (False || False)
, the evaluation should stop at the firstTrue
because the final outcome is already known.This is not done for performance reasons but for safety. In other programming languages, it is common to do things like
n < len(vector) && vector[n]
, where the shortcut acts as a prevention system to avoid accessing illegal memory locations accidentally.