2.3. Evaluating Scheme Expressions
Let's turn to a discussion of how Scheme evaluates the expressions you type. We have already established the rules for constant objects such as strings and numbers; the object itself is the value. You have probably also worked out in your mind a rule for evaluating procedure applications of the form (procedure arg1 … argn). Here, procedure is an expression representing a Scheme procedure, and arg1 … argn are expressions representing its arguments. One possibility is the following.Find the value of procedure.
Find the value of arg1.⋮
Find the value of argn.
Apply the value of procedure to the values of arg1 … argn.
For example, consider the simple procedure application (+ 3 4). The value of + is the addition procedure, the value of 3 is the number 3, and the value of 4 is the number 4. Applying the addition procedure to 3 and 4 yields 7, so our value is the object 7.Section 3.1 summarizes the core syntactic forms and introduces the syntactic extension mechanism.Before we go on to more syntactic forms and procedures, two points related to the evaluation of procedure applications are worthy of note. First, the process given above is overspecified, in that it requires the subexpressions to be evaluated from left to right. That is, procedure is evaluated before arg1, arg1 is evaluated before arg2, and so on. This need not be the case. A Scheme evaluator is free to evaluate the expressions in any order|left to right, right to left, or any other sequential order. In fact, the subexpressions may be evaluated in different orders for different applications even in the same implementation.The second point is that procedure is evaluated in the same manner as arg1 … argn. While procedure is often a variable that names a particular procedure, this need not be the case. Exercise 2.2.3 had you determine the value of ((car (list + - * /)) 2 3). Here, procedure is (car (list + - * /)). The value of (car (list + - * /)) is the addition procedure, just as if procedure were simply the variable +.Exercise 2.3.1.
Write down the steps necessary to evaluate the expression below.
((car (cdr (list + - * /))) 17 5)