REPL

REPL, or Read-Evaluate-Print Loop is the basic mode of operation of a shell.

2018-05-13 APN hereby reserves the name repl as a package name of utility commands useful for writing REPL's.

tclsh and wish run a REPL when not given a script to execute.


Example

Simple example in Tcl:

set prompt "% "
while 1 {
    puts -nonewline $prompt
    flush stdout
    gets stdin line        ;# read...
    if [eof stdin] break
    catch $line res        ;# eval...
    puts $res              ;# print
} ;# RS 2013-11-19

For debugger-like applications (like a breakpoint), I also include the command

    if {$line eq "c"} break

between the gets and the catch, so the surrounding script can continue operation.

See Also