The Mwnci REPL

REPL stands for “Read Eval Print Loop”. Basically it’s the console for evaluating Mwnci commands.

The REPL reads input, sends it to the interpreter for evaluation, prints the result/output of the interpreter and starts again. Read, Eval, Print, Loop.

To start with the REPL, just type mwnci and press enter

nobby@reggie> mwnci
Mwnci 0.1.9.r14-20241208-042504
mwnci>

If all is well, then you will see something similar to the above, with the cursor waiting patiently at the end of mwnci>

We can now enter our first command, so we’ll start with the standard “Hello World”

Mwnci 0.1.9.r14-20241208-042504
mwnci> println("Hello World")
mwnci>  

And majestically, another prompt appears. So where’s the output?
Due to a (very) bad decision by the author, a command or group of commands needs to be delimited by a colon (:) before anything is evaluated (executed).

Mwnci 0.1.9.r14-20241208-042504
mwnci> println("Hello World")
mwnci> :
Hello World
null
mwnci>

The last return value is also shown. In this case it’s null because the println command doesn’t need a return response other than output the requested text.

The colon doesn’t need to be on a separate line.

Mwnci 0.1.9.r14-20241208-042504
mwnci> println("Hello World")
mwnci> :
Hello World
null
mwnci> println("Hello World"):
Hello World
null

Now we can show how the colon works after entering several mwnci commands

mwnci> foreach n in 1..10 {
mwnci> println(n)
mwnci> }:
1
2
3
4
5
6
7
8
9
10
null
mwnci>

There is command line history for the REPL, using emacs bindings. So if you us the up arrow you can go back a line at a time. In this case a line is the succession of commands prior to the last colon. So if we press the up arrow you will see

mwnci> foreach n in 1..10 {
mwnci> println(n)
mwnci> }:
1
2
3
4
5
6
7
8
9
10
null
mwnci> foreach n in 1..10 { println(n) }

To exit the REPL and get back to the command line

mwnci> exit():
nobby@reggie>