Read–eval–print loop
≈ 3 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
A read–eval–print loop (REPL), also termed an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user; a program written in a REPL environment is executed piecewise. The term usually refers to programming interfaces similar to the classic Lisp machine interactive environment or to Common Lisp with the SLIME development environment. Common examples include command-line shells and similar environments for programming languages, and the technique is very characteristic of scripting languages, even though their characteristics can vary greatly.
A read–eval–print loop (REPL), also termed an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user; a program written in a REPL environment is executed piecewise. The term usually refers to programming interfaces similar to the classic Lisp machine interactive environment or to Common Lisp with the SLIME development environment. Common examples include command-line shells and similar environments for programming languages, and the technique is very characteristic of scripting languages, even though their characteristics can vary greatly. A minimal definition in Common Lisp is: (loop (print (eval (read)))) where read waits for user input and eval evaluates it. print prints the result, and loop loops indefinitely. You can enter (+ 1 1) and stop the loop with C-c .
Combining source files and REPL development
Developers of Lisp applications typically do not write or copy-paste code to a REPL. They use the REPL for quick tests, for debugging and to explore a running system. They write their application in a source file under version control, they use commands or keyboard shortcuts to compile their code interactively. The Lisp process is running and connected to their editor, and it compiles new code "on the fly", without restarting. In Common Lisp, developers typically compile the current function they are working on. They can also compile a whole file, or compile a whole project. When a function is compiled, they may get type warnings (specially with the SBCL implementation), and they can invoke the newly created function from the REPL. If an error occurs, they are given an interactive debugger. This process of compiling one single function and testing it on the REPL is very fast in comparison to other processes. The cycle of writing a new function, compiling it and testing is very short, and interactive, making it suitable for development. It also means that the application state is not lost during development. It is only when they choose to do so that they run or compile all the application from scratch.
Text derived from https://en.wikipedia.org/w/index.php?oldid=1356441599 under CC BY-SA 4.0; modifications have been made.