MJr is a probabilistic programming language based on pattern-rewriting, heavily inspired by MarkovJunior by Maxim Gumin. This project provides a compiler for the MJr programming language, which compiles MJr programs to JavaScript, TypeScript or Python 3.



More examples can be found in the models folder.


MJr programs can be compiled to JavaScript, TypeScript or Python 3. To use the compiled output in your project, you must also include the MJr runtime library:

The MJr program can then be used by calling its main function, which has the following signature:

function main(width: int, height: int, rng?: PRNG): Grid;

The return value is a Grid object with the following properties:

For convenience, Grid objects can also be converted to strings for display.

The rng parameter is optional; if provided, it must be an object with a nextDouble method returning a random floating-point value in the half-open interval [0, 1), and a nextInt method accepting a positive integer n and returning a random integer in the half-open interval [0, n). If not provided, a default unseeded algorithm is used.


See the documentation and implementation notes for more information.