# Introduction

[Metalang99](https://github.com/hirrolot/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](https://github.com/hirrolot/datatype99):

```c
#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](https://github.com/hirrolot/interface99):

```c
#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](https://hirrolot.gitbook.io/metalang99/syntax-and-semantics) and ending with various [testing, debugging, and error reporting](https://hirrolot.gitbook.io/metalang99/testing-debugging-and-error-reporting) facilities. For more information, please refer to the following material:

* [The official GitHub repository](https://github.com/hirrolot/metalang99);
* [The formal specification](https://github.com/hirrolot/metalang99/blob/master/spec/spec.pdf);
* [The Metalang99 standard library documentation](https://metalang99.readthedocs.io/en/latest/);
* [The list of publications about Metalang99](https://github.com/hirrolot/metalang99#publications).

Let's start!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hirrolot.gitbook.io/metalang99/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
