The REPL
Atomo's REPL (read evaluate print loop) is an interactive environment for reading expressions, evaluating them in some context, and printing the result.
The prompt is provided by the haskeline library, so it is readline
-like, with history navigation.
The input is parsed as a block of expressions, so you can separate multiple expressions with ;
or ,
, in which case they will be evaluated in sequence and the last value will be printed.
It's also intelligent about multiline input, catching "unexpected ending" parse errors and allowing you to finish the expression:
[0]> "foo .... bar" "foo\nbar" [1]> 1 + .... 2 3 [2]> { a = 1 .... a + 2 .... \ print .... } call 3 3
If the REPL jumps the gun and eats up your input before you're done and causes a parse error, an incomplete
restart is provided. Triggering this restart will let you keep adding input.
To exit the REPL, you can use Ctrl+C
or Ctrl+D
, followed by y
to confirm. Pressing Ctrl+C
twice will also force it to exit.
The REPL is implemented in Atomo, so you can use it in your code.
env basic-repl → @ok
Starts up the REPL with env
as the environment for evaluation.
Signals sent:
@prompt
Used to determine a prompt for the input line. To set your own, trigger the
use-prompt
restart with your prompt (a string) as an argument.@quit
Signaled when interaction receives an interrupt (usually by
Ctrl+C
) or end-of-input (usually byCtrl-D
).@(special: name)
Signaled when a special meta-command is entered. These are arbitrary strings preceded by a colon (
:
).For example, when the main REPL debugger is started, it asks for the restart to use in the form of
:1
,:2
, and so on. When these are entered,@(special: "1")
,@(special: "2")
etc. are signaled.@loop
Signaled after the REPL has evaluated and printed an input, and is about to start the loop over again.
env repl → @ok
Starts a full-blown REPL with env
as the environment for evaluation. This is what is run when you just say atomo
to start up Atomo's REPL - it wraps basic-repl
, providing a debugger, a different prompt, prompts before exiting.
Example:
[0]> 1 repl [0]> + 2 3 [1]> sqrt 1.0 [2]> really quit? (y/n) y @ok [3]>
Note that the [3]>
above is the outer REPL - as the inner one was signaling @loop
, its frame number increase as well.