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_all as m

class Number(m.Expression):
    def __add__(self, other: Number) -> Number:

    def from_int(cls, i: int) -> Number:

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

assert m.execute(Number.from_int(0) + Number.from_int(10)) == 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.