6.001 Recitation #7 Fall 1997 Prof. Albert R. Meyer 5-minute-problem #15: Controlling Order of Evaluation in The Metacircular Evaluator (posed in email, 11/14/97 for presentation Wed, 11/19) We might expect that with the precise code for a Scheme evaluator in front of us, we could figure out exactly the order in which it evaluates the subexpressions in a combination. The LIST-OF-VALUES procedure on page 367 of Chapter 4, Section 4.1 in SICP evaluates those subexpressions: (define (list-of-values exps env) (if (no-operands? exps) '() (cons (eval (first-operand exps) env) (list-of-values (rest-operands exps) env)))) But examining LIST-OF-VALUES, we realize that our metacircular evaluator inherits the order of evaluation that the underlying Scheme happens to use, so order of evaluation remains undetermined. Explain this observation to the class. Then show how to modify LIST-OF-VALUES so that it always evaluates expressions left to right -- likewise for right to left. SOLUTION LEFT TO RIGHT: (define (list-of-values exps env) (if (no-operands? exps) '() (let ((first-val (eval (first-operand exps) env))) (cons first-operand (list-of-values (rest-operands exps) env))))) RIGHT TO LEFT: (define (list-of-values exps env) (if (no-operands? exps) '() (let ((rest-vals (list-of-values (rest-operands exps) env))) (cons (eval (first-operand exps) env) rest-vals))))