Truth
Revision as of 19:15, 16 November 2023 by Marc Gurevitx (talk | contribs) (Created page with "In MiniScript certain statements and operations interpret their parts as being ''true'' or ''not true''. These are the conditions of the if and while statements, and t...")
In MiniScript certain statements and operations interpret their parts as being true or not true. These are the conditions of the if and while statements, and the operands of and, or and not operators [1].
Any MiniScript value - not only true and false values - can be used in these constructions. This is how they are interpreted:
Type | Considered false | Considered true |
---|---|---|
null | always false | |
number | 0 , false |
any non-zero number, including true, INFs and NaN |
string | empty string ("" ) |
non-empty strings |
list | empty list ([] ) |
non-empty lists |
map | empty map ({} ) |
non-empty maps |
funcRef | should always be true (but see this bug for a command-line version) |
Examples
if 0 then print "hi" // prints nothing
if 0/0 then print "hi" // prints "hi"
if [false] then print "hi" // prints "hi"
print 0 or {0:0} // prints 1
- ↑ Boolean operators treat numbers between 0 and 1 in a fuzzy manner