HigherOrderCO / Bend

A massively parallel, high-level programming language
https://higherorderco.com
Apache License 2.0
17.27k stars 425 forks source link

Request: Native boolean datatypes and operators #362

Open FranciscoJavierPizarro opened 4 months ago

FranciscoJavierPizarro commented 4 months ago

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 returns 1.

The boolean values should be like those in Python: True and False. 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, in True || (False || False), the evaluation should stop at the first True 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.

developedby commented 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