One easy way to get started at programming is to examine some typical interactions with an interpreter for the Scheme dialect of Lisp. Python language. Imagine that you are sitting at a computer terminal. You type an expression, a statement, and pass it to the interpreter, which then evaluates that expression. statement.
| Original | Python | |
| Original | Python | |
| One kind of primitive expression you might type is a number. | One kind of statement you might type is an expression. One kind of primitive expression is a number. |
Runbutton. Click on the primitive expression statement, and what happens is—nothing! To see the result of evaluating 486, we need to apply the function print to the expression, using the usual mathematical notation of function application print(486) resulting in the display of[1] 486 in a separate part in the browser window.
| Original | Python | |
|
There is no limit (in principle) to the depth of such nesting and to the overall complexity of the expressions that the Lisp interpreter can evaluate. It is we humans who get confused by still relatively simple expressions such as (+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6)) which the interpreter would readily evaluate to be 57. We can help ourselves by writing such an expression in the form (+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6)) following a formatting convention known as pretty-printing, in which each long combination is written so that the operands are aligned vertically. The resulting indentations display clearly the structure of the expression.[2] |
There is no limit (in principle) to the depth of such nesting and to the overall complexity of the expressions that the Python interpreter can evaluate. It is we humans who might get confused by still relatively simple expressions such as 3 * (2 * 4 + (3 + 5)) + ((10 - 7) + 6) which the interpreter would readily evaluate to be 57. We can help ourselves by writing such an expression in the form (3 * (2 * 4 + (3 + 5)) + ((10 - 7) + 6)) to visually separate the major components of the expression.[3] |
Even with complex expressions, the interpreter always operates in the same basic cycle: It reads an expression from the terminal, a statement typed by the user, evaluates the expression, statement, and prints the result of any applications of print. This mode of operation is often expressed by saying that the interpreter runs in a read-eval-print loop. read-evaluate-print loop. Observe in particular that it is not necessary to explicitly instruct the interpreter to print the value of the expression.[4] Observe, however, that it is necessary to explicitly instruct the interpreter to print the value of the expression.
Lisp programmers know the value of everything but the cost of nothing.