Exercise 4.2: Louis Reasoner plans to reorder the
cond clauses in eval so that the clause for procedure
applications appears before the clause for assignments. He argues that this
will make the interpreter more efficient: Since programs usually contain more
applications than assignments, definitions, and so on, his modified eval
will usually check fewer clauses than the original eval before
identifying the type of an expression.
What is wrong with Louis’s plan? (Hint: What will Louis’s evaluator do with
the expression (define x 3)?)
Louis is upset that his plan didn’t work. He is willing to go to any lengths
to make his evaluator recognize procedure applications before it checks for
most other kinds of expressions. Help him by changing the syntax of the
evaluated language so that procedure applications start with call. For
example, instead of (factorial 3) we will now have to write (call
factorial 3) and instead of (+ 1 2) we will have to write (call +
1 2).
练习 4.2:Louis Reasoner 打算重新排列 eval 中 cond 子句的顺序,使过程应用 (procedure applications) 的子句出现在赋值子句之前。他认为这会使解释器更高效:由于程序中通常包含的应用比赋值、定义等更多,他修改后的 eval 在识别表达式类型之前通常需要检查更少的子句。
Louis 的计划有何问题?(提示:Louis 的求值器对表达式 (define x 3) 会做什么?)
Louis 对他的计划失败感到沮丧。他愿意不惜一切代价让他的求值器在检查大多数其他类型的表达式之前先识别过程应用。请帮助他,通过改变被求值语言的语法,使过程应用以 call 开头。例如,原来写 (factorial 3) 的地方现在要写 (call factorial 3),原来写 (+ 1 2) 的地方现在要写 (call + 1 2)。