Skip to main content

Mini-language

The Playground mini-language is a simple expression language for declaring random variables and derived calculations.

Syntax

Statements are separated by ;. Each statement is either:

  • A random variable: <name> ~ <distribution>(<params>)
  • A derived variable: <name> = <expression>

Variable names must start with a letter and can contain letters, digits, and underscores.

x ~ norm(15, 3);
y ~ uniform(5, 10);
z = x * y;

Random variables

Declare a random variable using ~ and a distribution name:

revenue ~ norm(50000, 8000);
cost_ratio ~ uniform(0.4, 0.6);

Each simulation iteration draws a new sample from the distribution.

Derived variables

Declare a derived variable using = and a standard arithmetic expression:

profit = revenue - (revenue * cost_ratio);
margin_pct = profit / revenue * 100;

Supported operators: +, -, *, /, ** (power).

Variables are resolved in dependency order — you can reference a variable before declaring it.

Comments

Lines starting with # are ignored:

# Revenue model
revenue ~ norm(50000, 8000);

Histogram output

The histogram shows the distribution of the last declared variable across all iterations. If you want to visualize a specific variable, declare it last.

Error handling

Parse errors and undefined variable references show as an inline error message below the editor. The histogram clears on error.

Examples

Simple range estimate:

low ~ uniform(100, 200);
high ~ uniform(300, 500);
range = high - low;

Growth model:

initial_customers = 1000;
monthly_growth ~ norm(0.05, 0.01);
customers_year1 = initial_customers * (1 + monthly_growth) ** 12;

Probability of profit:

revenue ~ norm(100000, 15000);
costs ~ norm(80000, 10000);
profit = revenue - costs;

Then drag the Pr(x < X) line to 0 to read off the probability of a loss.