# Metalang99
[](https://github.com/hirrolot/metalang99/actions)
[](https://metalang99.readthedocs.io/en/latest/)
[](https://hirrolot.gitbook.io/metalang99/)
[](https://github.com/hirrolot/metalang99/blob/master/spec/spec.pdf)
> The dark side of the force is a pathway to many abilities, some considered to be unnatural.
-- Darth Sidious
Based on [`examples/demo.c`](examples/demo.c):
| Compile-time list manipulation |
| ```c // 3, 3, 3, 3, 3 static int five_threes[] = { ML99_LIST_EVAL_COMMA_SEP(ML99_listReplicate(v(5), v(3))), }; // 5, 4, 3, 2, 1 static int from_5_to_1[] = { ML99_LIST_EVAL_COMMA_SEP(ML99_listReverse(ML99_list(v(1, 2, 3, 4, 5)))), }; // 9, 2, 5 static int lesser_than_10[] = { ML99_LIST_EVAL_COMMA_SEP( ML99_listFilter(ML99_appl(v(ML99_greater), v(10)), ML99_list(v(9, 2, 11, 13, 5)))), }; ``` |
| Macro recursion |
| ```c #define factorial(n) ML99_natMatch(n, v(factorial_)) #define factorial_Z_IMPL(...) v(1) #define factorial_S_IMPL(n) ML99_mul(ML99_inc(v(n)), factorial(v(n))) ML99_ASSERT_EQ(factorial(v(4)), v(24)); ``` |
| Overloading on a number of arguments |
| ```c typedef struct { double width, height; } Rect; #define Rect_new(...) ML99_OVERLOAD(Rect_new_, __VA_ARGS__) #define Rect_new_1(x) \ { x, x } #define Rect_new_2(x, y) \ { x, y } static Rect _7x8 = Rect_new(7, 8), _10x10 = Rect_new(10); // ... and more! int main(void) { // Yeah. All is done at compile time. } ``` |