Programs

Ordinary Kiki cells recalculate automatically when their inputs change, while side effects such as writing a file or printing return a Task value that runs only when triggered.

Tasks

Functions such as print, write-file, and io.write-table return tasks. task expression can defer any expression explicitly.

:(Task void)

:(Task void)

:(Task (Task void))

A task is lazy: its body and arguments are evaluated when the task runs, not each time the document recalculates. This keeps a document containing pending writes safe to edit and inspect. In the editor, a task runs behind a button; see doc/ui.ki.

Running a program

kiki run file.ki evaluates the document and then runs its main value. main may be one task, a list of tasks run in order, or a zero-argument function that produces work.

Program arguments come after -- and are available through io.args. io.read-line reads standard input and returns null at the end; io.env reads an environment value.

:(fn -> (Task void) !stdin)

Reading and writing files

io.read-text reads a file as a string, while io.read-file returns raw bytes. Reads are reactive: when the source file changes, dependent cells update.

"hello"

["info boot complete" "warn cache cold" "info request /health" "error payment timeout" "info request /checkout"]

Writes return tasks and happen only when those tasks run:

:(Task void)

Tables use read-table and io.write-table; see doc/table.ki for schemas, CSV, and JSON.

Host capabilities

io.host operation payload asks the embedding application to perform a string-in, string-out capability. In an ordinary cell it is a reactive request; inside a task it becomes an action performed when that task runs.

:(fn -> string !host)

Host capabilities are the low-level bridge for features supplied by the Kiki app or another embedding. Prefer standard-library functions when one already describes the operation.

Where next

• doc/ui.ki — controls, buttons, and layout

• std/index.ki — the standard library