veradic repl
Experiment with declarations, statements and expressions in a persistent JIT session.
This chapter describes the terminal REPL. The browser IDE's REPL provides syntax tabs, history and suggestions around the same language, with Full proof initially selected instead of the terminal's advisory default.
veradic [GLOBAL OPTIONS] repl [--project FILE] [--syntax vada|varc|vibe]
--syntax defaults to vada; varc and vibe select the other two syntaxes. --project defaults to the current directory's verada.toml when present; the REPL finds library units in the project's source directories. The project's C files (c-sources) are compiled and loaded into the session when it starts, as run loads them, so inputs call the C functions its units import; its [proof] settings (the budget, the budget overrides and certificates) are how inputs are proved, with the proof workers prove uses by default (VERADA_JOBS, else half the cores).
A terminal uses line editing/history and prompts. Piped/script input echoes prompts and inputs into a transcript. It is not a machine-readable result protocol: input failures are reported and the session can continue; a normally ended REPL command returns 0 even after failing inputs. Use check/prove/run for CI result status.
Input and modes
Vada declarations/statements end in ;; an expression without ; prints its value. Varc uses its own declarations/calls with the same expression-versus-statement convention. Input can span lines; the prompt continues when the parser needs more, and a blank line forces submission. Later declarations shadow earlier names; they do not retroactively change compiled earlier code.
A generic instance an input declares (Vada's package Int_Vectors is new Verada.Containers.Unbounded.Vectors (Integer);) is compiled with that input, so later inputs call its subprograms.
Vibe input is Python, read as Python's own REPL reads it. A block (for ...:, def ...:, @dataclass and its class, a one-line if c: f()) keeps the prompt continuing until a blank line; so does a line that stops inside brackets or a triple-quoted string. A bare expression prints its value as print would (no leading space, unlike Vada's 'Image); a bare call of a procedure (a function returning None) runs it. Python's module level gives the meaning:
name = valuewith a name the session has no object of declares a session variable (its type inferred);name: T = valuealways declares one, andNAME: Final = valuea constant.name = valuewith a name the session already has assigns it, as Python assigns a global, so functions entered earlier see the new value; the value must have the object's type (declare it again with an annotation to change its type). Inside a block, assignments to the session's names assign them, and other names are the block's locals.def,classandtypedeclare,importnames library units, and anything else is a statement. Statements and declarations run in the order written: an input with a declaration after a statement (print(1); x = 1, or a pasted script) is entered as consecutive inputs, each piece's declarations before its statements, and a rejected piece stops the rest (the earlier pieces have run, as in Python).- A class from an earlier input constructs values as in a module (
Point(x=1, y=2)). Python's generic types are typed straight in (xs: list[int] = [],dict[str, int]), and are the same instances a build makes: each generic and its actuals is one library unit of the session from its first use, compiled then and not proved again (Verada's library is proved with Verada). A dataclass has its list, as in a module, solist[Point]in a later input is the type of the dataclass's own list; adictorsetof an earlier input's class is one only that input used.
Vibe functions can perform output and return a value. Their calling information is retained across accepted inputs, so later expressions, assignments and wrapper functions can use the result. For example, under strict proof:
def double(value: int) -> int:
requires(-1000 <= value <= 1000)
print("foo")
return value * 2Submit that definition, then double(5) prints foo and displays 10. :type double(5) reports int without printing or running the function. A function that only prints should declare -> None. The precondition above bounds the integer multiplication for strict proof; changing the submission shortcut does not bypass type, flow or proof checks.
Class support here includes dataclasses and the supported typed class forms. The plain-class transformation that derives fields and constructors from __init__ in source files is not yet applied to REPL inputs. Use a source file for those plain-class definitions; an ordinary undecorated class is currently rejected in the REPL even when its source-file form is valid.
verada> total = 0
verada> for i in range(1, 11):
| total += i
|
verada> total
55
verada> def twice(n: int) -> int:
| requires(n < 1000)
| return 2 * n
|
verada> print("twice", twice(total))
twice 110
The proof warnings this session prints are left out here.
verada> :set proof strict
verada> X : Natural := 1;
verada> X := X + 1;
verada> X
2
verada> :type X
Natural
Default proof is advisory: unproved conditions warn and their checks stay in the code. Strict rejects inputs with proof errors; off does no proof. Legality, flow and ownership checks always apply. Advisory keeps ghost code; strict and off erase it. In advisory and strict mode each pragma Assume (Varc's assume) is reported (B8002), as prove reports it.
An input is proved from what the session knows of its objects: an object's declared initial value until a statement of a later input may have changed it, and after that nothing but its type (after Z := 0;, 10 / Z in a later input does not prove).
In a Vibe session :type names types as Python does: int, float, str, bool, list[int], dict[int, str], a class by its name.
Every interactive command
| Command | Meaning / limits |
|---|---|
:help |
Display session syntax and commands |
:quit, :q |
Finalize session objects and leave; end-of-input also ends it |
:reset |
Finalize and forget every input, starting empty |
:memory |
Report number of live runtime heap objects, not OS resident bytes |
:set proof advisory |
Attempt proof, warn and run unproved inputs; default |
:set proof strict |
Reject inputs whose proof fails |
:set proof off |
Skip proof, retaining available runtime checks |
:prove |
Prove every entered input again strictly, without re-executing it or changing the selected mode |
:drop NAME |
Remove the input that declared NAME and free code/finalize its objects, if no later input depends on it |
:type EXPR |
Determine type without evaluating expression |
:with UNIT |
Add with/import visibility and load a library unit (with UNIT;, Varc's import UNIT;, Vibe's import UNIT) |
:load FILE |
Submit one file's declarations/statements as one input in the session syntax |
:explain CODE |
Print embedded explanation in session syntax |
:apl |
Each line is APL text over the session's names, until :apl again (APL) |
Colon-command arguments are split on whitespace: file paths with spaces and elaborate quoting are not a supported shell-like grammar. :load is not source watching or a hot-reload protocol. Library units, once loaded, keep their established identities during the session. Restart/reset appropriately after changing library source rather than assuming a second import rereads it.
Failure, lifetime and recovery
Accepted inputs execute immediately. A failed execution can leave an object written but undefined; subsequent uses can report B7010. Output, file effects and foreign mutations are not rolled back. Do not repeatedly use a poisoned object assuming its old value survives. Drop dependent inputs and its declaration where allowed, or reset the session and recreate state.
Dropping removes an entire declaring input, which may contain more than one declaration. If a later input needs it, drop that dependent input first. Reclaimed values finalize before their code is freed; reset/exit finalize in reverse session order. :memory can help observe lifetimes, but does not prove all external resources are closed.
The Vada session script exercises the commands, and the Vibe one the Vibe input forms; pipe either into veradic repl (with --syntax vibe for the second). The language server is a separate process and does not share a REPL's state. To debug native code, use build -g.