Conditionals¶
Minilang has several constructs for conditional evaluation of code.
Important
All conditional evaluation constructs treat only nil as the false-like or negative value, and all other values as true-like or positive. Boolean values (true and false) are not nil and hence treated as true-like or positive.
And / or expressions¶
These expressions check their left argument for nil and only evaluate their right argument if necessary.
They operate as follows:
Expression |
Result of |
|
Result |
|---|---|---|---|
|
|
No |
|
|
Not |
Yes |
|
|
|
Yes |
|
|
Not |
No |
|
If expressions¶
An if-expression evaluates its condition expressions and evaluates the then-block if the condition value is not nil. Otherwise it evaluates the else-block is present, or nil otherwise. Additional elseif branches can used to avoid nesting the else blocks.
The condition value itself can optionally contain a variable declaration using let or var (including an unpacking declaration) allowing a computed value such as a regular expression match to be used as the condition without needing an extra declaration.