🖊️
Metalang99
  • Introduction
  • Syntax and semantics
  • Partial application and function composition
  • Data model
  • Testing, debugging, and error reporting
  • Final words
Powered by GitBook
On this page

Was this helpful?

Introduction

NextSyntax and semantics

Last updated 5 months ago

Was this helpful?

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 :

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

#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));
}

Let's start!

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

;

;

;

.

Metalang99
Datatype99
Interface99
core metalanguage
testing, debugging, and error reporting
The official GitHub repository
The formal specification
The Metalang99 standard library documentation
The list of publications about Metalang99