-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathboolean.edh
37 lines (31 loc) · 1.39 KB
/
boolean.edh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# %%
# (and) and (or) are nullish testing boolean operators, almost the same as in
# Python.
#
# they don't require or coerce either operand to `Bool` type, and use `null()`
# testing semantic to decide which operand to return, so they respect magic
# method `__null__()` for object values (similar to `__bool__()` in Python)
#
# an important property of these operators are short-circuiting according to
# their left-hand operand.
#
# while magic method overrides are imposible to (and) and (or)
# %%
true or { console.print$ "impossible to get eval'ed"; false }
# %%
false and { console.print$ "impossible to get eval'ed"; true }
# %%
# (&&) and (||) are boolean operators potentially carrying bit-wise and/or
# vectorization semantics (as however implemented by magic methods from either
# operands). in case no magic method present, both operands are required to be
# of `Bool` type, or the operation is considered not applicable (NA is returned
# to the runtime), so they are guaranteed to return exact `true` or `false`
# value, where applicable and not overridden by some magic method.
#
# especially note they are NOT short-circuiting, i.e. both operands are
# guaranteed to be eval'ed, this is crucial for magic methods to always work
# with both left-hand and right-hand object values.
# %%
true || { console.print$ "surely get eval'ed"; false }
# %%
false && { console.print$ "surely get eval'ed"; true }