A read–eval–print loop (REPL), also known as an interactive toplevel or language shell, is a simple, interactive computer programming environment that takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user; a program written in a REPL environment is executed piecewise.
In a REPL, the user enters one or more expressions (rather than an entire compilation unit) and the REPL evaluates them and display the results.
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 arguments 1 2 3, yielding the result 6.
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.
Most recent example is Playground file. Without requiring you to compile and run a complete project, a playground provides quick feedback for the results of your coding experiments. You just need to select a .playground file in the project navigator in xcode, or create a .playground file by choosing File > New > File and selecting the Playground source template for your ios platform. Enter the code into the .playground file, and examine the results in the sidebar. The quick look option opens assistant editor which will open with a timeline view, containing a graph of these values over time.
Below is the exapmle for fibonacci series in playground in swift language on iOS platform.
In a REPL, the user enters one or more expressions (rather than an entire compilation unit) and the REPL evaluates them and display the results.
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 arguments 1 2 3, yielding the result 6.
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.
Most recent example is Playground file. Without requiring you to compile and run a complete project, a playground provides quick feedback for the results of your coding experiments. You just need to select a .playground file in the project navigator in xcode, or create a .playground file by choosing File > New > File and selecting the Playground source template for your ios platform. Enter the code into the .playground file, and examine the results in the sidebar. The quick look option opens assistant editor which will open with a timeline view, containing a graph of these values over time.
Below is the exapmle for fibonacci series in playground in swift language on iOS platform.
No comments:
Post a Comment