Numbers
Numbers are the smallest useful Wist values. They are used by arithmetic expressions, comparisons, conditions, loops and most shipped examples.
When to read this page
Read this page when you want to understand the numeric examples used by Wist dialects or when you are deciding whether a custom DSL needs only arithmetic or a broader language surface.
Goal
Understand numeric literals, arithmetic operators and the modules needed to run numeric expressions.
Minimal example
2 + 3 * 4Expected result:
14Multiplication binds before addition. Use parentheses when the intended order should be explicit:
(2 + 3) * 4Expected result:
20Required modules
A minimal arithmetic dialect uses:
use Arithmetic,Numbers,Scopes,WhitespacesThese modules cover numeric values, arithmetic operators, grouping and ordinary whitespace handling.
Arithmetic operators
The common arithmetic operators are:
| Operator | Meaning |
|---|---|
+ | addition |
- | subtraction |
* | multiplication |
/ | division |
The exact runtime numeric representation depends on the selected dialect and backend path. Native profiles may also enable native type and CIL-oriented optimizations.
Grouping
Parentheses group expressions:
(10 - 2) * (3 + 1)Expected result:
32Grouping is important in DSL examples because it makes intent readable even when precedence already defines the same result.
Numbers in larger programs
Numbers can be stored in variables when the active dialect includes variable support:
let price = 100
let fee = 5
price + fee * 2Expected result:
110This example is no longer arithmetic-only. It also needs Identifier and Variables.
Numbers in conditions
Numbers can participate in equality and comparison checks when the active dialect includes condition/comparison modules:
if 2 == 2 (1) else (0)Expected result:
1This requires more than Numbers and Arithmetic; it also needs condition and equality support.
Optimized numeric profiles
Some shipped dialects include native-oriented modules and optimizers. These are useful for performance-sensitive arithmetic, but they should be enabled after the basic semantics are already correct.
A native arithmetic profile may include optimizer flags such as:
enable ArithmeticOptimization
enable NativeCilOptimization
enable NativeTypesOptimizationDo not use optimizers to hide missing language semantics. First make the unoptimized or simpler path correct, then optimize.
Common mistakes
- Assuming arithmetic implies variables. It does not.
- Assuming arithmetic implies conditions. It does not.
- Using
compilermode with an interpreter-only arithmetic dialect. - Enabling native optimizers before testing the base expression behavior.
- Treating benchmark output as a substitute for semantic tests.
Next
Continue with Variables to use numeric values in named bindings.