In a REPL, the user may enter expressions, which are then evaluated, and the results displayed. The name read-eval-print loop comes from the names of the Lisp primitive functions which implement this functionality:
(+ 1 2 3), which is parsed into a linked list containing four data elements.
+is called on the arguments
1 2 3, yielding the result
6does not need much formatting to print.
The REPL is commonly misnamed an interpreter. This is an erroneous usage, since many programming languages that use compilation (including bytecode compilation) have REPLs, such as Common Lisp and Python.
Because the print function outputs in the same textual format that the read function uses for input, most results are printed in a form that could (if it's useful) be copied and pasted back into the REPL. However, it's sometimes necessary to print representations of opaque data elements that can't sensibly be read back in -- such as a socket handle or a complex class instance. In these cases, there must exist a syntax for unreadable objects -- in Python, it's the
<__module__.class instance> notation; in Common Lisp, the
# form. The REPL of CLIM and the Symbolics Lisp Machine can also read back unreadable objects. They record for each output which object was printed. Later when the code is read back, the object will be retrieved from the printed output.
A REPL can become an essential part of learning a new language as it gives quick feedback to the novice. Many tool-suites as well as programming languages use a REPL to allow algorithm exploration and debug, such as Matlab, SciPy and IPython. The doctest module of the Python programming language allows tests to be easily generated from the captured output of its REPL command line shell.
To implement a Lisp REPL, it is necessary only to implement these three functions and an infinite-loop function. (Naturally, the implementation of eval will be complicated, since it must also implement all the primitive functions like car and + and special operators like if.) This done, a basic REPL itself is but a single line of code: (loop (print (eval (read)))).
One possible implementation of eval is as a recursive interpreter that acts on the syntax tree created by read. Another possibility is to compile the syntax tree into machine code and execute it.
Complying with JCAHO's read-back requirement: take steps to reduce communication errors.(Joint Commission on Accreditation of Healthcare Organization)
Jun 01, 2004; Do all staff at your organization know what constitutes a critical test result? If not, this could cause you problems during your...