bool.h¶
Boolean algebra.
Defines
-
ML99_true(...)¶
Truth.
-
ML99_false(...)¶
Falsehood.
-
ML99_not(x)¶
Logical negation.
Examples
#include <metalang99/bool.h> // 1 ML99_not(v(0)) // 0 ML99_not(v(1))
-
ML99_and(x, y)¶
Logical conjunction.
Examples
#include <metalang99/bool.h> // 0 ML99_and(v(0), v(0)) // 0 ML99_and(v(0), v(1)) // 0 ML99_and(v(1), v(0)) // 1 ML99_and(v(1), v(1))
-
ML99_or(x, y)¶
Logical inclusive OR.
Examples
#include <metalang99/bool.h> // 0 ML99_or(v(0), v(0)) // 1 ML99_or(v(0), v(1)) // 1 ML99_or(v(1), v(0)) // 1 ML99_or(v(1), v(1))
-
ML99_xor(x, y)¶
Logical exclusive OR.
Examples
#include <metalang99/bool.h> // 0 ML99_xor(v(0), v(0)) // 1 ML99_xor(v(0), v(1)) // 1 ML99_xor(v(1), v(0)) // 0 ML99_xor(v(1), v(1))
-
ML99_boolEq(x, y)¶
Tests
x
andy
for equality.Examples
#include <metalang99/bool.h> // 1 ML99_boolEq(v(0), v(0)) // 0 ML99_boolEq(v(0), v(1)) // 0 ML99_boolEq(v(1), v(0)) // 1 ML99_boolEq(v(1), v(1))
-
ML99_boolMatch(x, matcher)¶
Matches
x
against the two cases: if it is 0 or 1.Examples
#include <metalang99/bool.h> #define MATCH_1_IMPL() v(Billie) #define MATCH_0_IMPL() v(Jean) // Billie ML99_boolMatch(v(1), v(MATCH_)) // Jean ML99_boolMatch(v(0), v(MATCH_))
Note
This function calls
f
with ML99_call, so no partial application occurs, and so arity specifiers are not needed.
-
ML99_boolMatchWithArgs(x, matcher, ...)¶
The same as ML99_boolMatch but provides additional arguments to all branches.
Examples
#include <metalang99/bool.h> #define MATCH_1_IMPL(x, y, z) v(Billie ~ x y z) #define MATCH_0_IMPL(x, y, z) v(Jean ~ x y z) // Billie ~ 1 2 3 ML99_boolMatchWithArgs(v(1), v(MATCH_), v(1, 2, 3)) // Jean ~ 1 2 3 ML99_boolMatchWithArgs(v(0), v(MATCH_), v(1, 2, 3))
-
ML99_if(cond, x, y)¶
If
cond
is true, evaluates tox
, otherwisey
.Examples
#include <metalang99/bool.h> // 123 ML99_if(v(1), v(123), v(18)) // 18 ML99_if(v(0), v(123), v(18))
-
ML99_IF(cond, x, y)¶
The plain version of ML99_if.
This macro can imitate lazy evaluation:
ML99_IF(<cond>, <term>, <another-term>)
will expand to one of the two terms, which can be evaluated further; if<cond>
is 0, then<term>
will not be evaluated, and the same with<another-term>
.Note
x
andy
can possibly expand to commas. It means that you can supplyML99_TERMS(...)
as a branch, for example.
-
ML99_TRUE(...)¶
-
ML99_FALSE(...)¶
-
ML99_NOT(x)¶
-
ML99_AND(x, y)¶
-
ML99_OR(x, y)¶
-
ML99_XOR(x, y)¶
-
ML99_BOOL_EQ(x, y)¶