Repository navigation
Syntax Reference
A program is a block { … } of declarations and flows, one per line, optionally
preceded by function definitions. Every glyph has an ASCII alias.
smooth:{ X ((▷X + X + ▽X) / 3.0) } /* a function of one */
{
INPUT:◯ □ 3 4 /* declare a 3x4 grid */
(smooth INPUT) → S /* one full sweep into S */
! (S >= -100.0) /* checked at compile time */
(S - INPUT) → = /* the caller's output */
}
| Glyph | ASCII | Meaning |
|---|---|---|
◯ □
|
matrix shape
|
NAME:◯ □ d0 d1 … declares a space of that shape |
→ |
-> |
Flow: one complete sweep of the grid into the target |
= |
The output; expr → = ends the pipeline |
|
⇒ |
=> |
Fixed point: expr ⇒ X sweeps until no cell moves by more than 𝜏 or --max-iter sweeps have run |
▷ ▽
|
>> <<
|
The cell before / after along an axis, zero at the edge; a digit picks the axis (▷0X), else the innermost with more than one cell |
◇+ ◇× ◇> ◇< |
<>+ … |
Fold: collapse an axis by sum, product, max, min; a digit picks the axis (◇+1 X) |
◈+ ◈× ◈> ◈< |
<.>+ … |
Scan: the running fold; keeps the shape |
□ (in an expression) |
[] |
Lift: □1 X inserts a length-1 axis, which then broadcasts |
⍳ |
# |
⍳0 X is each cell's coordinate along axis 0, from zero |
⌽ |
% |
k ⌽ X rotates by k (wrapping); ⌽X reverses |
⍴ |
\ |
2 3 ⍴ X reads X's cells, in order, into that shape |
⍉ |
' |
⍉X reverses the axes; 1 0 ⍉ X permutes them |
↑ ↓
|
^. _.
|
k ↑ X keeps the first k cells along an axis (the last for negative k); k ↓ X drops them |
⌷ |
~ |
I ⌷ X reads X at the position each cell of I names (floor), zero past its cells |
? |
? |
?X is a number in [0, 1) hashed from X's bits: random, without state |
⌈ ⌊
|
>. <.
|
Dyadic: the greater / the lesser; monadic (⌈X, ⌊X): ceiling / floor |
| |
| |
A | B is B modulo A with the sign of A; 0 | B is B |
+ - × / ^ |
+ - * / ^ |
Element-wise; a whole exponent is repeated multiplication |
< > <= >= == |
Masks: A > B is A where it holds, 0 elsewhere. No boolean type, no branch |
|
exp log sqrt sin cos abs ind |
Named functions; ind X is 1 where X is nonzero |
|
𝜏 |
τ |
The threshold constant, bound by --tau (default 0.0) |
name:{ params body } |
A function: an expression body, or flows ending in → =; called prefix (f A B) or, for two parameters, infix (A f B) |
|
&[0x…]:NAME:◯ □ … |
@ |
A space bound to an address the caller owns |
! |
A constraint checked at compile time, see Verification | |
$ |
Audit trace of the dataflow (--dump-dag) |
|
/* … */ // …
|
Comments |
Binding, tight to loose: prefix function calls; ⍳ ⌽ ⍴ ⍉ ↑ ↓ ⌷ and the shifts;
× /; ⌈ ⌊ |; + -; an infix call; the comparisons. Parenthesise anything
you are not sure of; the examples do.
Shapes are row-major: for [d0, …, dk], axis a has extent d_a and stride
product(d_{a+1..k}). Every flow's result has a shape the compiler computes;
a shift keeps it, a fold drops the axis, a lift adds one, a reshape sets it. Two
spaces meet element-wise when their shapes match, or when one has length 1
along an axis the other does not (broadcasting), which is what □ is for:
◇+1 (A × B) /* A: 2 3 1, B: 1 3 4 → a 2x4 matrix product */
(X - (□1 (◇+1 X))) /* subtract each row's sum from the row */
((□1 V) × (□0 V)) /* outer product of a vector with itself */
Each → is a complete sweep: every cell of the target is written before the
next flow begins, so a shift always reads a finished grid. expr ⇒ X needs X
to exist first (INPUT → X), reads the previous round whole, and stops on the
tolerance or the cap; the kernel reports which. A function whose body is flows
runs those flows every round when called inside ⇒.
mix:{ A B ((A × 0.5) + (B × 0.5)) }
step:{ U
(▷U + ▽U) → S
(S / 4.0) → =
}
{
INPUT:◯ □ 1024
(INPUT mix (step INPUT)) → =
}
A body sees its parameters, 𝜏 and constants, nothing of the caller's. Calls
are expanded at compile time, so a function costs nothing at run time and works
at any shape. A ⇒ inside a body is not allowed.
Cells are binary64 (--f32: binary32). In the circuit, --fixed W.F makes them
two's complement with F fraction bits; the interpreter on the same numbers is
the reference. Integers below 2^53 are exact in f64, so q | X is exact modular
arithmetic. Literals need a digit on both sides of the point (1.0, 0.5).
ρ (RHO) Language 1.0 · Apache-2.0 · Shogo Toda · Repository