truthiness - pannous/warp GitHub Wiki
Truthiness in angle
Angle stays close to python truthiness:
Falsey values are treated as no by if, while and and/or:
if '' then "truthy" else "falsy" // "falsy"
if 0.0 then "truthy" else "falsy" // "falsy"
if [] then "truthy" else "falsy" // "falsy"
if [0] then "truthy" else "falsy" // "truthy"
Falsy are no, 0 and 0.0, the empty text '', ø (nil, an unset reference), the empty groups (), {}, [], and
other empty objects, also of a known type (cat{}, an empty set or byte list). Everything else is truthy, including
{x:1}, [1], {x:0} and [0].
Falsy is not equal: only the number 0 equals false (the bool no is 0), so 0 == false is true while
'' == false and [] == false are false.
A "truthy" value will satisfy the check performed by if or while statements. We use "truthy" and "falsy" to differentiate from the bool values True and False.
This allows general natural usage of logic for ternary conditional operators:
a and b or c is similar to
if a then b else c
or/else ARE NOT IDENTICAL:
if 1 then 0 else 2 == 0
1 and 0 or 2 == 2 !!!
If statements could thus be realized without any special internal logic. Only because we want to capture all different ways of writing if expression is some special handling necessary. Search testIf function to see all variants.