Read–eval–print loop
From Wikipedia, the free encyclopedia
(Redirected from REPL)
This article's use of external links may not follow Wikipedia's policies or guidelines. Please improve this article by removing excessive or inappropriate external links, and converting useful links where appropriate into footnote references. (February 2012) |
This article does not cite any references or sources. Please help improve this article by adding citations toreliable sources. Unsourced material may be challenged and removed. (February 2012) |
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 F#, Smalltalk, Standard ML,Perl, Prolog, Scala, Python, Ruby, Haskell, APL, BASIC, J, 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 read function accepts an expression from the user, and parses it into a data structure in memory. For instance, the user may enter the s-expression
(+ 1 2 3)
, which is parsed into a linked list containing four data elements. - The eval function takes this internal data structure and evaluates it. In Lisp, evaluating an s-expression beginning with the name of a function means calling that function on the arguments that make up the rest of the expression. So the function
+
is called on the arguments1 2 3
, yielding the result6
. - The print function takes the result yielded by eval, and prints it out to the user. If it is a complex expression, it may be pretty-printed to make it easier to understand. In this example, though, the number
6
does not need much formatting to print.