Next: , Previous: Functions, Up: Language


2.8 Conditionals

Any value can be related to another value. 78 is less than 85. 2 equals 2. "Hi" is not "Bye". Enigma comes with a basic set of functions that can be used to test these relations. The functions greater, lesser, equal, not, or and and are available. These functions return either true or false. To run a function on the condition that a relational function has returned true, use the function act.

While lesser and greater are aimed at numbers only, and and, or and not are aimed at booleans only, equal can be used on all objects. It tests for all equalities.

2 = a;
4 = b;

a 2 ! add | temp b ! equal = cond1;
"47" ! num | temp 48 ! greater = cond2;

cond1 cond2 ! and | temp write stdout "4 = 4 and 47 > 48\n" ! act;
cond1 cond2 ! or | temp write stdout "4 = 4 or 47 > 48\n" ! act;
cond2 ! not | cond1 temp ! and | temp write stdout "4 = 4 and !(47 >
48)\n" ! act;

Even simpler, one can do this (though there's no real need for it):

# Instead of stdout "Hello" !write;
true write stdout "Hello" !act;