Metalang99 1.13.5
Full-blown preprocessor metaprogramming
Loading...
Searching...
No Matches
bool.h File Reference

Boolean algebra. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ML99_true(...)
 Truth.
#define ML99_false(...)
 Falsehood.
#define ML99_not(x)
 Logical negation.
#define ML99_and(x, y)
 Logical conjunction.
#define ML99_or(x, y)
 Logical inclusive OR.
#define ML99_xor(x, y)
 Logical exclusive OR.
#define ML99_boolEq(x, y)
 Tests x and y for equality.
#define ML99_boolMatch(x, matcher)
 Matches x against the two cases: if it is 0 or 1.
#define ML99_boolMatchWithArgs(x, matcher, ...)
 The same as ML99_boolMatch but provides additional arguments to all branches.
#define ML99_if(cond, x, y)
 If cond is true, evaluates to x, otherwise y.
#define ML99_IF(cond, x, y)
 The plain version of ML99_if.
#define ML99_TRUE(...)
#define ML99_FALSE(...)
#define ML99_NOT(x)
#define ML99_AND(x, y)
#define ML99_OR(x, y)
#define ML99_XOR(x, y)
#define ML99_BOOL_EQ(x, y)

Detailed Description

Boolean algebra.

Macro Definition Documentation

◆ ML99_AND

#define ML99_AND ( x,
y )
Value:
ML99_PRIV_AND(x, y)

◆ ML99_and

#define ML99_and ( x,
y )
Value:
#define ML99_and(x, y)
Logical conjunction.
Definition bool.h:62
#define ML99_call(op,...)
Invokes a metafunction with arguments.
Definition lang.h:33

Logical conjunction.

Examples

// 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))
Boolean algebra.
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145

◆ ML99_BOOL_EQ

#define ML99_BOOL_EQ ( x,
y )
Value:
ML99_PRIV_BOOL_EQ(x, y)

◆ ML99_boolEq

#define ML99_boolEq ( x,
y )
Value:
#define ML99_boolEq(x, y)
Tests x and y for equality.
Definition bool.h:130

Tests x and y for equality.

Examples

// 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

#define ML99_boolMatch ( x,
matcher )
Value:
#define ML99_boolMatch(x, matcher)
Matches x against the two cases: if it is 0 or 1.
Definition bool.h:153

Matches x against the two cases: if it is 0 or 1.

Examples

#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

#define ML99_boolMatchWithArgs ( x,
matcher,
... )
Value:
ML99_call(ML99_boolMatchWithArgs, x, matcher, __VA_ARGS__)
#define ML99_boolMatchWithArgs(x, matcher,...)
The same as ML99_boolMatch but provides additional arguments to all branches.
Definition bool.h:173

The same as ML99_boolMatch but provides additional arguments to all branches.

Examples

#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_FALSE

#define ML99_FALSE ( ...)
Value:
0

◆ ML99_false

#define ML99_false ( ...)
Value:
#define ML99_false(...)
Falsehood.
Definition bool.h:22
#define ML99_callUneval(ident,...)
Invokes a metafunction ident with unevaluated arguments.
Definition lang.h:42

Falsehood.

◆ ML99_IF

#define ML99_IF ( cond,
x,
y )
Value:
ML99_PRIV_UNTUPLE(ML99_PRIV_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 and y can possibly expand to commas. It means that you can supply ML99_TERMS(...) as a branch, for example.

◆ ML99_if

#define ML99_if ( cond,
x,
y )
Value:
ML99_call(ML99_if, cond, x, y)
#define ML99_if(cond, x, y)
If cond is true, evaluates to x, otherwise y.
Definition bool.h:191

If cond is true, evaluates to x, otherwise y.

Examples

// 123
ML99_if(v(1), v(123), v(18))
// 18
ML99_if(v(0), v(123), v(18))

◆ ML99_NOT

#define ML99_NOT ( x)
Value:
ML99_PRIV_NOT(x)

◆ ML99_not

#define ML99_not ( x)
Value:
#define ML99_not(x)
Logical negation.
Definition bool.h:39

Logical negation.

Examples

// 1
// 0

◆ ML99_OR

#define ML99_OR ( x,
y )
Value:
ML99_PRIV_OR(x, y)

◆ ML99_or

#define ML99_or ( x,
y )
Value:
#define ML99_or(x, y)
Logical inclusive OR.
Definition bool.h:84

Logical inclusive OR.

Examples

// 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_TRUE

#define ML99_TRUE ( ...)
Value:
1

◆ ML99_true

#define ML99_true ( ...)
Value:
#define ML99_true(...)
Truth.
Definition bool.h:17

Truth.

◆ ML99_XOR

#define ML99_XOR ( x,
y )
Value:
ML99_PRIV_XOR(x, y)

◆ ML99_xor

#define ML99_xor ( x,
y )
Value:
#define ML99_xor(x, y)
Logical exclusive OR.
Definition bool.h:107

Logical exclusive OR.

Examples

// 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))