Sesterl icon indicating copy to clipboard operation
Sesterl copied to clipboard

andalso, orelse

Open michallepicki opened this issue 4 years ago • 2 comments

I find myself needing to write more complicated boolean expressions. Ideally they would also be "lazy" so wouldn't compute the right expression if left expression already gives the result.

I searched for them and only found this commit.

Are such operators (or "functions" with special semantics) planned?

michallepicki avatar Sep 16 '21 19:09 michallepicki

I guess andalso is if left then right else false and orelse is if left then true else right

michallepicki avatar Sep 16 '21 22:09 michallepicki

Yes, I understand the need for short circuit logical operators, but I haven’t decided how to provide them; they can be implemented as:

  1. special built-in operators (like Erlang’s andalso and orelse), or
  2. macros (after introducing some type-safe mechanism for writing macros).

The first one is easy to realize but somewhat ad-hoc, while the second one seems theoretically elegant and general but a bit tough to achieve.

gfngfn avatar Sep 17 '21 11:09 gfngfn