This page is the reference for the .flux language surface. Grammar
extensions and their rationale are recorded as ADRs (the parser grammar is
normative in the specification’s appendices); this page presents the surface
you write every day.
Program structure
Section titled “Program structure”A .flux file contains top-level declarations:
| Declaration | Syntax | Purpose |
|---|---|---|
| Component | compo Name(props…) |
A UI component with an indented body |
| Record | record Name { field: Type, … } |
A data type with named fields |
| Const binding | Name.field = expr |
A top-level constant (used by color.flux, font.flux) |
Components (compo)
Section titled “Components (compo)” Row gap: 8.0 Text text: task.label Button text: "Remove", onPress: || { tasks.remove(task) }- A
compodeclares typed props in parentheses and owns an indented body. - Children indent beneath a view call that carries at least one named prop — this is what lets the indentation-delimited grammar distinguish a child block from a sibling.
- Prop defaults are written inline:
enabled: Bool = true.
State signals
Section titled “State signals”Two equivalent forms declare a reactive signal at the top of a compo:
compo Counter $count: Int = 0 // sigil form
compo Counter2 state count: Int = 0 // keyword formAn assignment inside a handler writes the signal. Written signals propagate through the dependency graph, and only nodes whose props read a written signal re-materialize — see host-authoritative state.
Derived values (let)
Section titled “Derived values (let)”let total: Float = items * priceA let declares a read-only binding computed from signals. It recomputes
when a written signal reaches it; do not mirror it into a second signal.
Closures
Section titled “Closures”| Form | Shape | Used for |
|---|---|---|
| Zero-argument | || { count = count + 1 } |
Handler props (onPress, onChange) |
| Named parameter | fn(v) { newTask = v } |
Callbacks that receive the event value |
| Key function | fn(t) { t.label } |
ForEach keys |
| Lambda child | { item => TaskRow(task: item, …) } |
ForEach item rendering |
View calls and props
Section titled “View calls and props”A view call names a stdlib component and carries named props:
TextInput text: $newTask, onChangeText: fn(v) { newTask = v }, placeholder: "What needs doing?"- Props are comma-separated
name: valuepairs on one line. text: $signaltwo-way binds the prop to a signal (used byTextInput).- Handlers are closures; their bodies compile to bytecode the host VM runs.
Interpolation and operators
Section titled “Interpolation and operators”Text text: "tapped {count} times"{expr} inside a string literal interpolates a value into the prop. The
expression surface includes arithmetic, comparison, optional chaining with
?., and the ?? fallback operator:
Text text: name ?? "Loading..."Control flow: ForEach and routing
Section titled “Control flow: ForEach and routing”Router initialRouteName: "tasks" Screen route: "tasks" …ForEach renders a list with a key function; Router/Screen/RouterNav
drive navigation. See the navigation guide.
| Type | Written as | Notes |
|---|---|---|
| Primitives | String, Int, Float, Bool |
|
| List | List[Task] |
Mutable through append/remove/clear |
| Optional | Option[String] |
Unwrap with ?? fallback |
| Record | declared record types |
Field access with . |
| Color | Color |
Presets red/green/blue/black/white |
| Font | Font, Weight, Style |
Presets body/title/caption |
The stdlib value types live in stdlib/prelude.flux (Option,
Alignment, Overflow, KeyboardType, ContentMode, Ref, Handler)
and stdlib/traits.flux (Numeric, Eq, Show).
Next steps
Section titled “Next steps”- The stdlib reference for every component’s props.
- The CLI reference to run the language.
