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(...) ML99_callUneval(ML99_true, )
| Truth.
#define | ML99_false(...) ML99_callUneval(ML99_false, )
| Falsehood.
#define | ML99_not(x) ML99_call(ML99_not, x)
| Logical negation.
#define | ML99_and(x, y) ML99_call(ML99_and, x, y)
| Logical conjunction.
#define | ML99_or(x, y) ML99_call(ML99_or, x, y)
| Logical inclusive OR.
#define | ML99_xor(x, y) ML99_call(ML99_xor, x, y)
| Logical exclusive OR.
#define | ML99_boolEq(x, y) ML99_call(ML99_boolEq, x, y)
| Tests `x` and `y` for equality.
#define | ML99_boolMatch(x, matcher) ML99_call(ML99_boolMatch, x, matcher)
| Matches `x` against the two cases: if it is 0 or 1.
#define | ML99_boolMatchWithArgs(x, matcher, ...) ML99_call(ML99_boolMatchWithArgs, x, matcher, __VA_ARGS__)
| The same as ML99_boolMatch but provides additional arguments to all branches.
#define | ML99_if(cond, x, y) ML99_call(ML99_if, cond, x, y)
| If `cond` is true, evaluates to `x`, otherwise `y`.
#define | ML99_IF(cond, x, y) ML99_PRIV_UNTUPLE(ML99_PRIV_IF(cond, (x), (y)))
| The plain version of ML99_if.
#define | ML99_TRUE(...) 1
#define | ML99_FALSE(...) 0
#define | ML99_NOT(x) ML99_PRIV_NOT(x)
#define | ML99_AND(x, y) ML99_PRIV_AND(x, y)
#define | ML99_OR(x, y) ML99_PRIV_OR(x, y)
#define | ML99_XOR(x, y) ML99_PRIV_XOR(x, y)
#define | ML99_BOOL_EQ(x, y) ML99_PRIV_BOOL_EQ(x, y)

## Detailed Description

Boolean algebra.

## Macro Definition Documentation

## ML99_and

#define ML99_and | ( |  | x,
|  |  | y
| ) |  | ML99_call(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))
bool.h
Boolean algebra.
ML99_and
#define ML99_and(x, y)
Logical conjunction.
Definition bool.h:62
v
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145

## ML99_boolEq

#define ML99_boolEq | ( |  | x,
|  |  | y
| ) |  | ML99_call(ML99_boolEq, x, y)

Tests `x` and `y` 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_boolEq
#define ML99_boolEq(x, y)
Tests x and y for equality.
Definition bool.h:130

## ML99_boolMatch

#define ML99_boolMatch | ( |  | x,
|  |  | matcher
| ) |  | ML99_call(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_))
ML99_boolMatch
#define ML99_boolMatch(x, matcher)
Matches x against the two cases: if it is 0 or 1.
Definition bool.h:153

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,
|  |  | ...
| ) |  | ML99_call(ML99_boolMatchWithArgs, x, matcher, __VA_ARGS__)

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_boolMatchWithArgs
#define ML99_boolMatchWithArgs(x, matcher,...)
The same as ML99_boolMatch but provides additional arguments to all branches.
Definition bool.h:173

## ML99_if

#define ML99_if | ( |  | cond,
|  |  | x,
|  |  | y
| ) |  | ML99_call(ML99_if, cond, x, y)

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

# 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
#define ML99_if(cond, x, y)
If cond is true, evaluates to x, otherwise y.
Definition bool.h:191

## ML99_IF

#define ML99_IF | ( |  | cond,
|  |  | x,
|  |  | y
| ) |  | 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_not

#define ML99_not | ( |  | x | ) | ML99_call(ML99_not, x)

Logical negation.

# Examples

#include <metalang99/bool.h>
// 1
ML99_not(v(0))
// 0
ML99_not(v(1))
ML99_not
#define ML99_not(x)
Logical negation.
Definition bool.h:39

## ML99_or

#define ML99_or | ( |  | x,
|  |  | y
| ) |  | ML99_call(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_or
#define ML99_or(x, y)
Logical inclusive OR.
Definition bool.h:84

## ML99_xor

#define ML99_xor | ( |  | x,
|  |  | y
| ) |  | ML99_call(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_xor
#define ML99_xor(x, y)
Logical exclusive OR.
Definition bool.h:107