REPL
rad repl starts an interactive session. You type Rad, it runs it, and
whatever you define stays defined until you leave.
$ rad repl
🤙 Rad REPL v0.12.0
Type ':help' for help, ':exit' or Ctrl+D to quit.
> name = "world"
> upper(name)
"WORLD"
An expression prints its value; an assignment prints nothing. Values print the
way you would write them, so a string comes back quoted and you can tell "5"
from 5. print() is still there when you want the unquoted form.
Blocks take several lines¶
A block construct keeps taking lines until you enter a blank one. Rad scopes
blocks by indentation, so there is no closing token to look for - the blank
line is what says you are done. The prompt changes to . while the REPL is
still gathering, and the next line is indented for you.
> fn greet(name):
. print("hi {name}")
.
> greet("world")
hi world
Everything with a body works this way: if, for, while, switch, named
fn, and catch: blocks. A blank line also gets you out of a buffer you would
rather abandon - though Ctrl+C is quicker, and throws the whole thing away.
Pasting a multi-line block works too. The REPL can tell a pasted newline from a pressed Enter, so the whole snippet arrives before anything runs.
Mistakes don't end the session¶
An error prints the same diagnostic it would print in a script, and then you get your prompt back:
> x = 5
> undefined_variable
error[RAD20028]: Undefined variable: undefined_variable
--> <repl>:1:1
|
1 | undefined_variable
| ^^^^^^^^^^^^^^^^^^
|
= info: rad docs RAD20028
> x
5
Ctrl+C interrupts whatever is running - a slow shell command, an HTTP request, a loop that turned out to be infinite - and returns you to the prompt with the session intact. Press it twice if something is truly wedged; the second one exits immediately.
Editing¶
The line you are typing is editable:
| Key | Does |
|---|---|
← → |
move the cursor |
Ctrl+A / Ctrl+E |
jump to start / end of line |
Ctrl+W |
delete the word behind the cursor |
Ctrl+K |
delete to end of line |
Ctrl+U |
delete the line |
↑ ↓ |
recall earlier input |
Ctrl+C |
abandon this line |
Ctrl+D |
leave (on an empty line) |
Inside a multi-line block, ↑ and ↓ move between the lines you are typing
and only reach for history once the cursor is already at the top or bottom.
History lasts for the session and is not written to disk.
Commands¶
A line starting with : is a REPL command rather than Rad:
| Command | Does |
|---|---|
:help |
the summary |
:vars |
variables you have defined |
:docs <topic> |
docs for a function, an error code, or a guide page |
:load <file> |
run a .rad file into this session |
:clear |
clear the screen |
:reset |
forget every variable and start over |
:exit, :quit |
leave |
:docs takes anything rad docs takes:
> :docs upper
> :docs RAD20028
> :docs guide/shell-commands
:load runs a file's statements against your session, so the functions and
variables it defines are yours afterwards. It is the way to work on a script
and try its pieces without pasting them.
Two things behave differently than in a script¶
defer runs at the end of the turn that registered it, not when the
session ends. A turn is the REPL's whole notion of a script. Holding a defer
until you quit would mean it does nothing observable for as long as you keep
working, and never runs at all if a later turn ends badly.
args blocks, command blocks, and file headers are refused. All three
describe how a script is invoked from a command line, and a session was not
invoked from one. Put the script in a file and :load it, or run it normally
to exercise its argument parsing. See
RAD20049 for the details.
Piping input¶
With no terminal to draw on - a pipe, CI, an agent's tool call - rad repl
reads lines and prints results without drawing a prompt:
$ printf 'x = 20\nx * 2\n' | rad repl
🤙 Rad REPL v0.12.0
Type ':help' for help, ':exit' or Ctrl+D to quit.
40
Blocks work the same way, blank line and all. This is also how the REPL's own tests drive it.
What it doesn't do yet¶
No tab completion, no syntax highlighting, no Ctrl+R search, and no history
file that survives the session. None of these are ruled out; they just aren't
built.