Exercise 5.48: The compile-and-go
interface implemented in this section is awkward, since the compiler can be
called only once (when the evaluator machine is started). Augment the
compiler-interpreter interface by providing a compile-and-run primitive
that can be called from within the explicit-control evaluator as follows:
;;; EC-Eval input:
(compile-and-run
'(define (factorial n)
(if (= n 1)
1
(* (factorial (- n 1)) n))))
;;; EC-Eval value:
ok
;;; EC-Eval input:
(factorial 5)
;;; EC-Eval value:
120
练习 5.48:本节实现的 compile-and-go 接口比较笨拙,因为编译器只能被调用一次(在求值器机器启动时)。通过提供一个可从显式控制求值器内部调用的 compile-and-run 基本过程,扩充编译器与解释器之间的接口,用法如下:
;;; EC-Eval input:
(compile-and-run
'(define (factorial n)
(if (= n 1)
1
(* (factorial (- n 1)) n))))
;;; EC-Eval value:
ok
;;; EC-Eval input:
(factorial 5)
;;; EC-Eval value:
120
;;; EC-Eval input:
(compile-and-run
'(define (factorial n)
(if (= n 1)
1
(* (factorial (- n 1)) n))))
;;; EC-Eval value:
ok
;;; EC-Eval input:
(factorial 5)
;;; EC-Eval value:
120