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

Natural numbers: [0; 255]. More...

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

Go to the source code of this file.

Macros

#define ML99_inc(x)
 \(x + 1\)
#define ML99_dec(x)
 \(x - 1\)
#define ML99_natMatch(x, matcher)
 Matches x against the two cases: if it is zero or positive.
#define ML99_natMatchWithArgs(x, matcher, ...)
 The same as ML99_natMatch but provides additional arguments to all branches.
#define ML99_natEq(x, y)
 \(x = y\)
#define ML99_natNeq(x, y)
 \(x \neq y\)
#define ML99_greater(x, y)
 \(x > y\)
#define ML99_greaterEq(x, y)
 \(x \geq y\)
#define ML99_lesser(x, y)
 \(x < y\)
#define ML99_lesserEq(x, y)
 \(x \leq y\)
#define ML99_add(x, y)
 \(x + y\)
#define ML99_sub(x, y)
 \(x - y\)
#define ML99_mul(x, y)
 \(x * y\)
#define ML99_div(x, y)
 \(\frac{x}{y}\)
#define ML99_divChecked(x, y)
 Like ML99_div but returns ML99_nothing() is x is not divisible by y, otherwise ML99_just(result).
#define ML99_mod(x, y)
 Computes the remainder of division.
#define ML99_add3(x, y, z)
 \(x + y + z\)
#define ML99_sub3(x, y, z)
 \(x - y - z\)
#define ML99_mul3(x, y, z)
 \(x * y * z\)
#define ML99_div3(x, y, z)
 \(\frac{(\frac{x}{y})}{z}\)
#define ML99_min(x, y)
 \(min(x, y)\)
#define ML99_max(x, y)
 \(max(x, y)\)
#define ML99_assertIsNat(x)
 Emits a fatal error if x is not a natural number, otherwise results in emptiness.
#define ML99_INC(x)
#define ML99_DEC(x)
#define ML99_NAT_EQ(x, y)
#define ML99_NAT_NEQ(x, y)
#define ML99_DIV_CHECKED(x, y)
#define ML99_NAT_MAX   255
 The maximum value of a natural number, currently 255.

Detailed Description

Natural numbers: [0; 255].

Most of the time, natural numbers are used for iteration; they are not meant for CPU-bound tasks such as Fibonacci numbers or factorials.

Macro Definition Documentation

◆ ML99_add

#define ML99_add ( x,
y )
Value:
#define ML99_call(op,...)
Invokes a metafunction with arguments.
Definition lang.h:33
#define ML99_add(x, y)
Definition nat.h:211

\(x + y\)

Examples

#include <metalang99/nat.h>
// 11
ML99_add(v(5), v(6))
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145
Natural numbers: [0; 255].

◆ ML99_add3

#define ML99_add3 ( x,
y,
z )
Value:
#define ML99_add3(x, y, z)
Definition nat.h:306

\(x + y + z\)

Examples

#include <metalang99/nat.h>
// 15
ML99_add3(v(1), v(6), v(8))

◆ ML99_assertIsNat

#define ML99_assertIsNat ( x)
Value:
#define ML99_assertIsNat(x)
Emits a fatal error if x is not a natural number, otherwise results in emptiness.
Definition nat.h:397

Emits a fatal error if x is not a natural number, otherwise results in emptiness.

Examples

#include <metalang99/nat.h>
#define F_IMPL(x) ML99_TERMS(ML99_assertIsNat(v(x)), ML99_inc(v(x)))
// 6
ML99_call(F, v(5))
// A compile-time number mismatch error.
ML99_call(F, v(blah))

◆ ML99_DEC

#define ML99_DEC ( x)
Value:
ML99_PRIV_DEC(x)

◆ ML99_dec

#define ML99_dec ( x)
Value:
#define ML99_dec(x)
Definition nat.h:51

\(x - 1\)

Examples

#include <metalang99/nat.h>
// 4
Note
If x is 0, the result is ML99_NAT_MAX.

◆ ML99_div

#define ML99_div ( x,
y )
Value:
#define ML99_div(x, y)
Definition nat.h:255

\(\frac{x}{y}\)

Examples

#include <metalang99/nat.h>
// 3
ML99_div(v(12), v(4))
Note
A compile-time error if \(\frac{x}{y}\) is not a natural number.

◆ ML99_div3

#define ML99_div3 ( x,
y,
z )
Value:
#define ML99_div3(x, y, z)
Definition nat.h:350

\(\frac{(\frac{x}{y})}{z}\)

Examples

#include <metalang99/nat.h>
// 5
ML99_div(v(30), v(3), v(2))
Note
A compile-time error if \(\frac{(\frac{x}{y})}{z}\) is not a natural number.

◆ ML99_DIV_CHECKED

#define ML99_DIV_CHECKED ( x,
y )
Value:
ML99_PRIV_DIV_CHECKED(x, y)

◆ ML99_divChecked

#define ML99_divChecked ( x,
y )
Value:
#define ML99_divChecked(x, y)
Like ML99_div but returns ML99_nothing() is x is not divisible by y, otherwise ML99_just(result).
Definition nat.h:276

Like ML99_div but returns ML99_nothing() is x is not divisible by y, otherwise ML99_just(result).

Examples

#include <metalang99/nat.h>
// ML99_just(3)
// ML99_nothing()
// ML99_nothing()

◆ ML99_greater

#define ML99_greater ( x,
y )
Value:
#define ML99_greater(x, y)
Definition nat.h:146

\(x > y\)

Examples

#include <metalang99/nat.h>
// 1
ML99_greater(v(8), v(3))
// 0
ML99_greater(v(3), v(8))

◆ ML99_greaterEq

#define ML99_greaterEq ( x,
y )
Value:
#define ML99_greaterEq(x, y)
Definition nat.h:163

\(x \geq y\)

Examples

#include <metalang99/nat.h>
// 1
// 0

◆ ML99_INC

#define ML99_INC ( x)
Value:
ML99_PRIV_INC(x)

◆ ML99_inc

#define ML99_inc ( x)
Value:
#define ML99_inc(x)
Definition nat.h:35

\(x + 1\)

Examples

#include <metalang99/nat.h>
// 6
Note
If x is ML99_NAT_MAX, the result is 0.

◆ ML99_lesser

#define ML99_lesser ( x,
y )
Value:
#define ML99_lesser(x, y)
Definition nat.h:180

\(x < y\)

Examples

#include <metalang99/nat.h>
// 1
ML99_lesser(v(3), v(8))
// 0
ML99_lesser(v(8), v(3))

◆ ML99_lesserEq

#define ML99_lesserEq ( x,
y )
Value:
#define ML99_lesserEq(x, y)
Definition nat.h:197

\(x \leq y\)

Examples

#include <metalang99/nat.h>
// 1
ML99_lesserEq(v(8), v(8))
// 0
ML99_lesserEq(v(8), v(3))

◆ ML99_max

#define ML99_max ( x,
y )
Value:
#define ML99_max(x, y)
Definition nat.h:378

\(max(x, y)\)

Examples

#include <metalang99/nat.h>
// 7
ML99_max(v(5), v(7))

◆ ML99_min

#define ML99_min ( x,
y )
Value:
#define ML99_min(x, y)
Definition nat.h:364

\(min(x, y)\)

Examples

#include <metalang99/nat.h>
// 5
ML99_min(v(5), v(7))

◆ ML99_mod

#define ML99_mod ( x,
y )
Value:
#define ML99_mod(x, y)
Computes the remainder of division.
Definition nat.h:292

Computes the remainder of division.

Examples

#include <metalang99/nat.h>
// 2
ML99_mod(v(8), v(3))
Note
A compile-time error if y is 0.

◆ ML99_mul

#define ML99_mul ( x,
y )
Value:
#define ML99_mul(x, y)
Definition nat.h:239

\(x * y\)

Examples

#include <metalang99/nat.h>
// 12
ML99_mul(v(3), v(4))

◆ ML99_mul3

#define ML99_mul3 ( x,
y,
z )
Value:
#define ML99_mul3(x, y, z)
Definition nat.h:334

\(x * y * z\)

Examples

#include <metalang99/nat.h>
// 24
ML99_mul3(v(2), v(3), v(4))

◆ ML99_NAT_EQ

#define ML99_NAT_EQ ( x,
y )
Value:
ML99_PRIV_NAT_EQ(x, y)

◆ ML99_NAT_NEQ

#define ML99_NAT_NEQ ( x,
y )
Value:
ML99_PRIV_NOT(ML99_NAT_EQ(x, y))

◆ ML99_natEq

#define ML99_natEq ( x,
y )
Value:
#define ML99_natEq(x, y)
Definition nat.h:112

\(x = y\)

Examples

#include <metalang99/nat.h>
// 1
ML99_natEq(v(5), v(5))
// 0
ML99_natEq(v(3), v(8))

◆ ML99_natMatch

#define ML99_natMatch ( x,
matcher )
Value:
#define ML99_natMatch(x, matcher)
Matches x against the two cases: if it is zero or positive.
Definition nat.h:74

Matches x against the two cases: if it is zero or positive.

Examples

#include <metalang99/nat.h>
#define MATCH_Z_IMPL() v(Billie)
#define MATCH_S_IMPL(x) v(Jean ~ x)
// Billie
ML99_natMatch(v(0), v(MATCH_))
// Jean ~ 122
ML99_natMatch(v(123), v(MATCH_))
Note
This function calls f with ML99_call, so no partial application occurs, and so arity specifiers are not needed.

◆ ML99_natMatchWithArgs

#define ML99_natMatchWithArgs ( x,
matcher,
... )
Value:
ML99_call(ML99_natMatchWithArgs, x, matcher, __VA_ARGS__)
#define ML99_natMatchWithArgs(x, matcher,...)
The same as ML99_natMatch but provides additional arguments to all branches.
Definition nat.h:94

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

Examples

#include <metalang99/nat.h>
#define MATCH_Z_IMPL(x, y, z) v(Billie ~ x y z)
#define MATCH_S_IMPL(n, x, y, z) v(Jean ~ n ~ x y z)
// Billie ~ 1 2 3
ML99_natMatchWithArgs(v(0), v(MATCH_), v(1, 2, 3))
// Jean ~ 122 ~ 1 2 3
ML99_natMatchWithArgs(v(123), v(MATCH_), v(1, 2, 3))

◆ ML99_natNeq

#define ML99_natNeq ( x,
y )
Value:
#define ML99_natNeq(x, y)
Definition nat.h:129

\(x \neq y\)

Examples

#include <metalang99/nat.h>
// 0
ML99_natNeq(v(5), v(5))
// 1
ML99_natNeq(v(3), v(8))

◆ ML99_sub

#define ML99_sub ( x,
y )
Value:
#define ML99_sub(x, y)
Definition nat.h:225

\(x - y\)

Examples

#include <metalang99/nat.h>
// 6
ML99_sub(v(11), v(5))

◆ ML99_sub3

#define ML99_sub3 ( x,
y,
z )
Value:
#define ML99_sub3(x, y, z)
Definition nat.h:320

\(x - y - z\)

Examples

#include <metalang99/nat.h>
// 3
ML99_sub3(v(8), v(2), v(3))