Truth

From MiniScript Wiki
Jump to navigation Jump to search

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
  1. Boolean operators treat numbers between 0 and 1 in a fuzzy manner