Introduction

Metalang99 is a functional macro language that allows you to create useful metaprograms in pure C99. Implemented as a header-only library, Metalang99 extends the standard C preprocessor with extra programming capabilities, including recursion, algebraic data types, collections, currying, natural numbers, functional composition, debugging facilities, and more.

Having Metalang99 at our disposal, it becomes possible to extend the C programming language with custom syntax sugar, via such advanced metaprograms as Datatype99:

#include <datatype99.h>

datatype(
    BinaryTree,
    (Leaf, int),
    (Node, BinaryTree *, int, BinaryTree *)
);

int sum(const BinaryTree *tree) {
    match(*tree) {
        of(Leaf, x) return *x;
        of(Node, lhs, x, rhs) return sum(*lhs) + *x + sum(*rhs);
    }

    return -1;
}

Or Interface99:

#include <interface99.h>

#include <stdio.h>

#define Shape_IFACE                      \
    vfunc( int, perim, const VSelf)      \
    vfunc(void, scale, VSelf, int factor)

interface(Shape);

typedef struct {
    int a, b;
} Rectangle;

int  Rectangle_perim(const VSelf) { /* ... */ }
void Rectangle_scale(VSelf, int factor) { /* ... */ }

impl(Shape, Rectangle);

typedef struct {
    int a, b, c;
} Triangle;

int  Triangle_perim(const VSelf) { /* ... */ }
void Triangle_scale(VSelf, int factor) { /* ... */ }

impl(Shape, Triangle);

void test(Shape shape) {
    printf("perim = %d\n", VCALL(shape, perim));
    VCALL(shape, scale, 5);
    printf("perim = %d\n", VCALL(shape, perim));
}

Throughout this book, you will learn the fundamentals of Metalang99, starting from the core metalanguage and ending with various testing, debugging, and error reporting facilities. For more information, please refer to the following material:

Also, stay tuned to our official mailing list, where you can see some important news about Metalang99 and participate in discussions.

Let's start!

Last updated