|
A read-eval-print loop (REPL), also known as an interactive toplevel, is a simple, interactive computer programming environment. The term is most usually used to refer to a Lisp interactive environment, but can be applied to command line shells and similar environments for Smalltalk, Python, Haskell, APL, BASIC, J, Scheme, TCL, and other languages as well. 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:
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
AdvantagesA 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. ImplementationTo 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. Major language environments and associated REPLs
External links
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.
Mercedes Car
This site monitored by SitePinger.net