灯下 登录
计算机科学 / SICP / 4.1.1 The Core of the Evaluator

Exercise 4.1 · 习题

Exercise 4.1: Notice that we cannot tell whether
the metacircular evaluator evaluates operands from left to right or from right
to left. Its evaluation order is inherited from the underlying Lisp: If the
arguments to cons in list-of-values are evaluated from left to
right, then list-of-values will evaluate operands from left to right;
and if the arguments to cons are evaluated from right to left, then
list-of-values will evaluate operands from right to left.

Write a version of list-of-values that evaluates operands from left to

right regardless of the order of evaluation in the underlying Lisp. Also write

a version of list-of-values that evaluates operands from right to left.

练习 4.1:注意,我们无法判断元循环求值器是从左到右还是从右到左对运算对象求值。它的求值顺序继承自底层的 Lisp:如果 list-of-values 中对 cons 的参数从左到右求值,那么 list-of-values 就会从左到右对运算对象求值;如果对 cons 的参数从右到左求值,那么 list-of-values 就会从右到左对运算对象求值。

请写一个 list-of-values 的版本,无论底层 Lisp 的求值顺序如何,都从左到右对运算对象求值。再写一个从右到左对运算对象求值的版本。