Exercise 4-1 Original
Exercise 4.1. Notice that we cannot-whether the Metacircular evaluator evaluates operands from left to right or from right to left. Its evaluation order was inherited from the underlying lisp:if the arguments to cons in List-of-values was evaluated from Left-to-right, then list-of-values'll evaluate operands from left to right; And if the arguments to cons is evaluated from right to left, then list-ofvalues'll evaluate operands from right to Lef T.write A version of List-of-values that evaluates operands from left to right regardless of the order of evaluation in th e underlying Lisp. Also write a version of List-of-values that evaluates operands from right to left.
Analysis
As stated in the question, the order of evaluation of list-of-values is determined by the parameters of cons. Also use No-operands to judge the Exps, if True then return null. And the left and right points, in let in the order of evaluation can be determined. If it is from left to right, it should be evaluated first and then rest, and finally constructed together with cons.
Code
(Define (list-of-values-l-to-r exps env) (if (no-operands exps)‘() (let ( (first (eval first-operand exps) env) ) ) (let ( (rest (list-of-values-l-to-r ( Rest-operands exps) env) ) ) (cons First rest) ) ) )) (Define (list-of-values-r-to-l exps env) (if (no-operands exps)‘() (let ( (rest (list-of-values-r-to-l ( rest-operands exps) env) ) ) ( Span class= "Hljs-title" >let ( (first (eval first-operand exps) env) ) ) ( cons First rest) ) ) ))
"SICP Exercise" 145 Exercise 4.1