Examples
This page collects complete Wist programs and shows which dialect shape they belong to.
Use these examples as small executable references, not as a full language specification.
When to read this page
Read this page after the Syntax Tour when you want complete snippets that can be copied into examples, tests or dialect documentation.
Goal
Connect Wist syntax examples to the dialects and modules that make them valid.
Minimal arithmetic
Program:
2 + 3 * 4Expected result:
14Typical dialect:
dialect MinimalArithmetic
use Arithmetic,Numbers,Scopes,Whitespaces
backend interpreterThis is the best first example because it proves that the basic parser, arithmetic modules and interpreter path are working.
Grouped arithmetic
Program:
(2 + 3) * 4Expected result:
20Use this when documenting precedence and grouping.
Variables and reassignment
Program:
let x = 5
x = x + 1
xExpected result:
6Typical modules:
use Arithmetic,Numbers,Identifier,Variables,Scopes,WhitespacesThis example proves that declaration, lookup and reassignment work together.
Variable-based formula
Program:
price + fee * 2With inputs:
price = 100
fee = 5Expected result:
110This is useful for pricing-style DSLs. Keep the dialect narrow and avoid enabling unrelated runtime features.
Conditional expression
Program:
let x = 2
if x == 2 (10) else (20)Expected result:
10Typical modules:
use Conditions,Equality,Arithmetic,Numbers,Identifier,Variables,Scopes,WhitespacesAdd ComparisonConditions when using operators such as <, <=, > or >=.
While loop accumulator
Program:
let sum = 0
let i = 1
while i <= 5 (
sum = sum + i
i = i + 1
)
sumExpected result:
15The while condition does not have to be parenthesized when it parses as one expression node. The loop body remains grouped because it contains multiple operations.
Typical modules:
use Loops,Variables,Identifier,Arithmetic,Numbers,ComparisonConditions,Scopes,WhitespacesUse this to test loop execution, variable mutation and backend parity.
Full default for example
Program:
let sum = 0
for (let i = 1) (i <= 5) (i = i + 1) (
sum = sum + i
)
sumExpected result:
15This is the shipped full-default example shape. It is useful for validating a broader Wist dialect over both interpreter and compiler modes. The current for parser expects initialization, condition, update and body to be grouped.
Nested loop aggregate
Program:
let total = 0
let outer = 1
while outer <= 3 (
let inner = 1
while inner <= 2 (
total = total + (outer * inner)
inner = inner + 1
)
outer = outer + 1
)
totalExpected result:
18Use this only for dialects that intentionally allow nested loops, local declarations and mutation.
Interop expression in trusted profiles
Program:
NumbersModule.Core.RealNumberImpl.Add(2, 5)Expected result:
7This belongs to trusted full profiles that include CSharpInterop. Do not use this example for restricted formula dialects.
Choosing examples for documentation
Use the smallest example that proves the concept:
| Concept | Recommended example |
|---|---|
| First run | 2 + 3 * 4 |
| Grouping | (2 + 3) * 4 |
| Variables | let x = 5; x = x + 1; x |
| Conditions | if x == 2 (10) else (20) |
| Loops | sum from 1 to 5 |
| Backend parity | same arithmetic/loop source in both modes |
| Restricted formula DSL | price + fee * 2 |
Common mistakes
- Using a broad full-default example to document a restricted DSL.
- Showing interop in user-facing formula documentation.
- Using loop examples before explaining variables and comparisons.
- Treating parenthesized
whileconditions as the only valid form. - Forgetting to mention which dialect or modules make an example valid.
- Treating examples as complete language specification.
Next
Continue with Build DSLs to turn these examples into explicit dialect profiles.