A pure, functional subset of Python for scientific computing
A versioned standard with a formal grammar, formal semantics, and a reference checker for a side-effect-free subset of Python.
Overview
PurePy defines a pure, side-effect-free subset of Python. It is aimed initially at researchers in programming languages and pedagogy, and is intended to grow into a common language for scientific computing, supporting portable applications in modelling, data processing, analysis, and visualisation.
The standard defines a versioned formal grammar, a formal semantics, and a reference checker. Every compliant implementation accepts any valid PurePy program and behaves according to the formal semantics.
from dataclasses import dataclass
from typing import Any
@dataclass
class Point:
x: Any
y: Any
def describe(p):
match p:
case Point(0, 0):
return "origin"
case Point(x, y):
return "point"
print(describe(Point(3, 4)))Why PurePy
Pure & functional
No side effects. Functions are referentially transparent.
Pythonic
A strict subset of Python: every valid PurePy program is valid Python, and runs with exactly the same runtime behaviour.
Formally specified
A grammar, well-formedness rules, and an operational semantics.
Portable
Python dialects are compliant by definition, checked on CPython, PyPy, and GraalPy. Research languages like Fluid and Fortl can be too.
For science
Reproducible, deterministic, and easy to reason about.
Checkable
A reference checker decides membership of the subset and flags use of unassigned variables.
