Introducing Kiki Lang
Kiki is a statically typed language where prose, tables, queries, and functions live in one plain-text .ki file. It aims for the live surface of a spreadsheet without positional cell references, and the structure of code without splitting a tool across Markdown, SQL, and Python.
This post is itself a .ki file. Every result below is evaluated by the Kiki compiler.
Prose first, code after >
Most languages treat prose as comments inside code. Kiki inverts the default: ordinary lines are prose, and lines starting with > are code.
> hours = 38
> rate = 45
> pay = fn h r -> h * r
> pay hours rate
1710
Prose splices evaluated expressions with \(...). Styling primitives such as bold, italic, and link are ordinary functions, and ~ passes trailing text as a prose value. Writing \(hours) hours come to $\(pay hours rate), calculated \(bold ~ live). produces:
38 hours come to $1710, calculated live.
Top-level definitions form a reactive dataflow graph rather than an imperative script: when an input changes, only the cells downstream of it recompute.
Tables, queries, and presentation values
Tables are first-class literal values written directly in text. _ marks a missing (null) cell:
> shifts = |Name Day Hours Bonus|
Ana Mon 8 _
Ana Tue 6 25.00
Ben Mon 9 _
Ben Wed 9 40.00
Cleo Tue 8 _
Queries are relational pipelines chained with |>:
> usd = format.money "USD"
> by-person = shifts
|> group Name Days = (count-distinct Day) Hours = (sum Hours) Bonus = (sum Bonus)
|> extend Pay = (Hours * 35 + Bonus |> usd)
|> sort -Pay
> by-person
| Name | Days | Hours | Bonus | Pay |
|---|---|---|---|---|
| Ben | 2 | 18 | 40.00 | 670.00 |
| Ana | 2 | 14 | 25.00 | 515.00 |
| Cleo | 1 | 8 | 0 | 280 |
Notice (Hours * 35 + Bonus |> usd). A common wart in spreadsheets and reporting SQL is that formatting a number turns it into text, breaking downstream arithmetic and sorting "$90" after "$120". In Kiki, usd attaches presentation metadata to the :decimal value without changing its type—sort -Pay still sorts numerically, and downstream sums still return a :decimal:
> by-person |> aggregate sum Pay |> usd
$1,465.00
Static types and inline tests
Types are inferred across scalars, records, lists, functions, and tables, so most definitions omit annotations. Inspecting shifts shows its inferred column schema, including :decimal? from the _ cells:
> type-of shifts
:|Name = string Day = string Hours = int Bonus = decimal?|
Referencing a nonexistent column (shifts |> select Hourse) or adding incompatible types fails typechecking on that line before evaluation runs.
Tests are written inline with => right next to the rules they verify. Pattern matching and tagged variants (one-of) express domain rules without boilerplate:
> overtime-pay = fn :decimal rate :int h ->
math.min h 40 * rate + math.max (h - 40) 0 * rate * 1.5
> contract = :(one-of hourly = {rate = decimal hours = int} salaried = decimal)
> weekly-pay = fn 'hourly c -> overtime-pay c.rate c.hours
fn 'salaried flat -> flat
> weekly-pay (:contract 'hourly {rate = 30 hours = 44}) => 1380 ✓
> weekly-pay (:contract 'salaried 1500) => 1500 ✓
A file is also a module: marking definitions with export lets sibling .ki files import shared tables, formats, and tested functions via import "./records".
One mechanism for errors, nulls, state, and tasks
Rather than separate language rules for exceptions, SQL three-valued NULL, reactive hooks, and async I/O, Kiki models all four as typed algebraic effects:
- Checked errors: Operations that can fail raise an effect with
!. The compiler tracks unhandled effects in the function's inferred type, and callers canhandleandresume:
> safe-ratio = fn :int a :int b ->
handle !div-by-zero -> resume 0
a / b
> safe-ratio 10 0
0
> type-of (fn :int a :int b -> a / b)
:(fn int int -> decimal !div-by-zero)
- Missing values: Using an optional
:T?where:Tis expected raises!null.or-elsehandles!nulllocally rather than propagating three-valued boolean logic through comparisons:
> shifts |> filter Hours >= 8 |> select Name Hours (Bonus or-else 0 |> usd)
| Name | Hours | Bonus |
|---|---|---|
| Ana | 8 | 0 |
| Ben | 9 | 0 |
| Ben | 9 | 40.00 |
| Cleo | 8 | 0 |
- User-defined effects: Functions can perform custom effects and resume with a value supplied by the caller's handler:
> subtotal = fn amount -> amount + !tax amount
> handle !tax x -> resume (x * 0.08)
subtotal 100
108.00
- Reactive state and deferred tasks: Reading an interactive
statecontrol performs an effect that registers the cell with the scheduler. Mutations (table.insert,table.update,write-file) construct suspendedTaskvalues instead of running during evaluation, so recalculating a page never triggers side effects—only activating abuttonor running a CLImainexecutes them.
Interactive controls and table lineage
Wrapping a default value in state declares a session-scoped control whose value feeds into any query:
> who = state ((choice ["Everyone" "Ana" "Ben" "Cleo"]) "Everyone")
> shifts |> filter who == "Everyone" or Name == who
| Name | Day | Hours | Bonus |
|---|---|---|---|
| Ana | Mon | 8 | |
| Ana | Tue | 6 | 25.00 |
| Ben | Mon | 9 | |
| Ben | Wed | 9 | 40.00 |
| Cleo | Tue | 8 |
Interactive controls and inline edits work live when this page is open in Kiki — open this post in the editor to change the picker above or edit the queries and tables.
In the interactive editor, queries over a literal table (filter, sort, select, lookup) also preserve cell lineage: each projected cell remembers its source row and column, so editing a cell inside a filtered view or clicking a projected button column updates the underlying .ki table text directly.
Implementation notes
Kiki is written in Zig, with a columnar in-memory table engine and a register VM. The same codebase compiles to a native CLI and to WebAssembly, so the compiler, query engine, and editor all run locally in the browser.
Kiki targets operational documents and working datasets that fit in memory rather than analytical warehouses. The language is still young—syntax and diagnostics are evolving. The Kiki compiler is not yet open sourced, and we plan to open source it in the future.
Explore it
Everything below runs locally in your browser via WebAssembly with no sign-up:
- Open this post in the live editor — edit any table or formula above and toggle between
Use,Edit,Code, andSourceviews - Kiki for programmers — single-page tour of types, functions, queries, and effects
- Build a tool — how tables,
fieldforms, row buttons, andrecords.kimodules fit together - Sample tools — complete multi-page workspaces (a coffee roaster, bike repair shop, design studio, and community food bank) written in
.ki