metadslΒΆ

Domain Specific Languages Embedded in Python

metadsl inserts a layer between calling a function and computing its result, so that we can build up a bunch of calls, transform them, and then execute them all at once.

from __future__ import annotations
import metadsl


class Number(metadsl.Expression):
    @metadsl.expression
    def __add__(self, other: Number) -> Number:
        ...

    @metadsl.expression
    @classmethod
    def from_int(cls, i: int) -> Number:
        ...


@metadsl.rule
def add_zero(y: Number):
    yield Number.from_int(0) + y, y
    yield y + Number.from_int(0), y


assert metadsl.execute(
    Number.from_int(0) + Number.from_int(10), add_zero
) == Number.from_int(10)

Seperating the user facing API of your DSL from its implementation enables other library authors to experiment with how it executes while preserving user expectations.

In this documentation we give some examples of using metadsl, provide a roadmap, and lay out the motivation for this library.