8.2. REPL

REPL (read-evel-print loop) is an interactive shell of Kink language. The core functionality of REPL is provided by kink/repl/REPL mod.

8.2.1. Start and stop REPL

To start REPL, execute kink command without spec-and-argv args (see commandline format).

REPL itself does not provide line editing or completion. Thus, in Unix-like environments, using rlwrap is recommended. For example:

$ rlwrap kink

In windows environment, Command Prompt provides a basic line editing function. Thus, it might be enough to just invoking kink command.

> kink

To exit from REPL, kill the JVM process by pressing Ctrl+C.

8.2.2. Usage of REPL

REPL reads a Kink program from stdin, and writes the result of repr method of the result of the program.

kink#0001:0001> 1 + 2 + 3
  6

kink#0002:0001> 'foo' + 'bar'
  "foobar"

REPL reports a compile error if the input is not a valid program.

kink#0001:0001> 1 + 2 + + 3
  compile error: unexpected token: [kink#0001 L1 C9] 1 + 2 + -->+ 3

REPL continues reading from stdin while the program can be valid with more input.

kink#0001:0001> 1 +
kink#0001:0002\ 2 +
kink#0001:0003\ 3
  6
kink#0002:0001> 'foo' +
kink#0002:0002\ 'bar'
  "foobar"

An environment is shared among execution of programs. Thus, you can use local variables to store data.

kink#0001:0001> :dbl <- {(:N)
kink#0001:0002\   N * 2
kink#0001:0003\ }
  nada
kink#0002:0001> :A <- 21
  nada
kink#0003:0001> dbl(A)
  42

If the program raises an exception, the exception traces are printed to stdout.

kink#0001:0001> 10 // 0
  exception traces: from oldest to newest
  [startup]
  [builtin:kink-mods/kink/_startup/STARTUP.kn L236 C3 _startup_aux] -->_startup_aux(Args Dep)
  [builtin:kink-mods/kink/_startup/STARTUP.kn L219 C11 try] CONTROL.-->try(
  [builtin:kink-mods/kink/CONTROL.kn L204 C19 reset] :handler = KONT.-->reset('kink/CONTROL-try'){
  [builtin:kink-mods/kink/CONTROL.kn L205 C10 body] :R = -->body
  [..snip..]
  [read_config]
  [builtin:kink-mods/kink/_java/CALL_AUX.kn L12 C3 cont] -->cont(
  [builtin:kink-mods/kink/javahost/JAVA_INPUT.kn L88 C9 if] -->if(Bin.nonempty?
  [builtin:kink-mods/kink/javahost/JAVA_INPUT.kn L90 C13 present_cont] -->present_cont(Bin)
  [builtin:kink-mods/kink/io/WRAP_SCANNER.kn L177 C13 loop] -->loop(Prefix)
  [builtin:kink-mods/kink/io/WRAP_SCANNER.kn L149 C5 branch] -->branch(
  [builtin:kink-mods/kink/io/WRAP_SCANNER.kn L151 C40 with_just_or] S.Buf.search_slice(S.Ind "\n").-->with_just_or(
  [builtin:kink-mods/kink/io/WRAP_SCANNER.kn L156 C13 present_cont] -->present_cont(Result)
  [builtin:kink-mods/kink/repl/REPL.kn L151 C17 compile] PROGRAM.-->compile(Program){(:Conf)
  [builtin:kink-mods/kink/PROGRAM.kn L66 C3 _compile_raw] -->_compile_raw(
  [builtin:kink-mods/kink/PROGRAM.kn L118 C3 handler] -->handler
  [builtin:kink-mods/kink/PROGRAM.kn L125 C16 success_cont] JAVA.wrap{ -->success_cont($compiled_fun) }
  [builtin:kink-mods/kink/repl/REPL.kn L117 C15 try] CONTROL.-->try(
  [builtin:kink-mods/kink/CONTROL.kn L204 C19 reset] :handler = KONT.-->reset('kink/CONTROL-try'){
  [builtin:kink-mods/kink/CONTROL.kn L205 C10 body] :R = -->body
  [builtin:kink-mods/kink/repl/REPL.kn L118 C11 program] { -->program(Conf.Binding) }
  [kink#0001 L1 C4 op_intdiv] 10 -->// 0
  exception message: Num.op_intdiv: zero division: 10 is divided by 0

8.2.3. Cancel the input

When you want to cancel the input of a program, insert EOF.

In Unix like systems, type Control+D to insert EOF.

kink#0003:0001> 10 +
kink#0003:0002\ 20 +
kink#0003:0003\ (type Control-D here)
kink#0004:0001>

In Windows, type Control+Z and the return key to insert EOF.

kink#0003:0001> 10 +
kink#0003:0002\ 20 +
kink#0003:0003\ (type Control-Z and the return key here)
kink#0004:0001>

When you insert EOF in the beginning of the program, it terminates REPL.