One easy way to get started at programming is to examine some typical interactions with an interpreter for the Scheme dialect of Lisp. JavaScript language. Imagine that you are sitting at a computer terminal. You type an expression, a statement, and the interpreter responds by displaying the result of its evaluating that expression. statement.
Original | JavaScript | |
One kind of primitive expression you might type is a number. | One kind of statement you might type is an expression statement, which consists of an expression followed by a semicolon. One kind of primitive expression is a number. |
Runbutton. Click on the primitive expression statement, and see what happens!
Original | JavaScript | |
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.[1] |
There is no limit (in principle) to the depth of such nesting and to the overall complexity of the expressions that the JavaScript interpreter can evaluate. It is we humans who might get confused by still relatively simple expressions such as 3 * 2 * (3 - 5 + 4) + 27 / 6 * 10; which the interpreter would readily evaluate to be 57. We can help ourselves by writing such an expression in the form 3 * 2 * (3 - 5 + 4) + 27 / 6 * 10; to visually separate the major components of the expression. |
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. 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.[2] statement.[3]
Lisp programmers know the value of everything but the cost of nothing.