Skip to content

REPL

The REPL (read-eval-print loop) runs Kiwi code as you type it. Start it by running kiwi with no script, or with kiwi -i:

$ kiwi
kiwi 1.8.0 - type 'exit' or press Ctrl+C to quit.
>>

The standard library is loaded, so every package is ready to use. Named arguments given on the command line are available through env::argv():

$ kiwi -name=ada
>> env::argv()
=> {"name": "ada"}

Each input runs as soon as you press Enter. When the input produces a value other than null, the REPL prints it after =>, so you rarely need println:

>> 1 + 2
=> 3
>> "hello".uppercase()
=> "HELLO"
>> x = 10
=> 10
>> [1 to 5].map(do (n) => n * x)
=> [10, 20, 30, 40, 50]
>> println "printed output"
printed output

Variables, functions and structs you define stay available for the rest of the session.

When a line opens a block (fn, if, for, struct and so on) the prompt changes to .. and the REPL waits until the block is complete:

>> fn square(n)
.. n * n
.. end
>> square(7)
=> 49

End a line with \ to continue a statement on the next line without opening a block:

>> total = 1 + \
.. 2 + 3
=> 6
KeysAction
← / →Move the cursor
Home / Ctrl+AStart of line
End / Ctrl+EEnd of line
Backspace / DeleteDelete before / at the cursor
Ctrl+KDelete to the end of the line
Ctrl+UDelete to the start of the line
Ctrl+WDelete the word before the cursor
↑ / ↓Previous / next history entry

Type exit or .exit, press Ctrl+D on an empty line, or press Ctrl+C.