Booleans

StackLang booleans are very conventional - there are literal true and false values formed by entering those symbols. These symbols are not commands, unlike the number constants.

A (possibly redundant) EBNF definition of booleans is given below.

true-symbol = "true" ;
false-symbol = "false" ;
boolean = true-symbol | false-symbol ;

Boolean-related Commands

Type Predicates

boolean? : Any -> Boolean
Produces true if input is a boolean, false otherwise.

false? : Any -> Boolean
Produces true if input is false, false otherwise.

true? : Any -> Boolean
Produces true if input is true, false otherwise.

Type Conversions

boolean-to-string : Boolean -> String
Produces the string "true" if input is true, "false" otherwise.

string-to-boolean : Boolean -> String
Produces a boolean as if the string were read in from the interpreter. Fails with a RuntimeError if string cannot be parsed.

Logical Operators

if : Boolean Any Any -> Any
If boolean is true, produces the third (furthest away from the active end) element. Else, produces the second element. Arguments to if must, as an effect of the evaluation rules, be evaluated before the evaluation of the if.

not : Boolean -> Boolean
Produces false if input is true, and true if input is false.

or : Boolean Boolean -> Boolean
Produces true if at least one input is true, false otherwise. This will not short-circuit.

and : Boolean Boolean -> Boolean
Produces false if at least one input is false, true otherwise. This will not short-circuit.

nor : Boolean Boolean -> Boolean
Produces false if at least one input is true, true otherwise.

xor : Boolean Boolean -> Boolean
Produces true if the two inputs are not the same, false otherwise.

nxor : Boolean Boolean -> Boolean
Produces true if the two inputs are the same, false otherwise.

nand : Boolean Boolean -> Boolean
Produces true if at least one input is false, false otherwise.

implies : Boolean Boolean -> Boolean
Produces true if the second implies (not the second or the first) the first.


Special Commands

eqv? : Any Any -> Boolean
Produces true if given elements are equal or equivalent.