zc-repl

zc-repl runs Zen C a line at a time. An expression prints its value; a statement, a function or a struct joins the session, and later lines can use it:

$ zc-repl
Zen C REPL (v0.5.1)
Type 'exit' or 'quit' to leave.
Type :help for commands.
zenc >>> let x = 5;
zenc >>> x * 2
10
zenc >>> fn square(n: int) -> int { return n * n; }
zenc >>> square(x)
25

A line with an open { or ( continues on the next one.

OptionWhat it does
-c <line>Runs one line and exits: zc-repl -c '1 + 2'.
-h, --helpLists the options.

Requirements

Each line compiles the session again and runs it, with the C compiler of the system (cc, or gcc on Windows; see Requirements). :run, :time, :type, :c and :vars call zc, so keep zc-repl next to it.

Commands

CommandWhat it does
:helpLists the commands and the keys.
:quitExits. exit, quit and Ctrl+D too.
:clearClears the screen.
:historyShows the lines of the session, numbered.
:undoRemoves the last line from the session.
:delete <n>Removes line n.
:edit [n]Edits line n (the last one, without n) in $EDITOR.
:resetEmpties the session.
:vars, :funcs, :structsLists the variables, functions or structs of the session.
:importsLists the imports of the session.
:show <name>Shows the declaration of a function or struct.
:type <expr>Shows the type of an expression.
:doc <name>Shows the documentation of a symbol.
:c <code>Shows the C of the session with code added.
:time <expr>Runs an expression 1000 times and shows how long it took.
:watch <expr>Prints the value of an expression after each line. :watch alone lists them.
:unwatch <n>Removes watch n.
:runRuns the whole session as a program.
:save <file>Saves the session to a .zc file.
:load <file>Loads a .zc file into the session.
:reloadLoads the plugins of the session again.
:plot <array>Draws a bar chart of the values of an array: :plot v.
! <cmd>Runs a shell command: ! ls.

Keys

KeyWhat it does
Up, DownPrevious and next line of the history.
TabCompletes a name.
Ctrl+A, Ctrl+EStart and end of the line.
Ctrl+U, Ctrl+KDeletes up to the start or the end of the line.
Ctrl+LClears the screen.

The session is saved to ~/.zenc_history on exit, and the next start loads it again: its variables and functions are still there. :reset empties it.