灯下 登录
计算机科学 / SICP / 4.2.2 An Interpreter with Lazy Evaluation

Exercise 4.27 · 习题

Exercise 4.27: Suppose we type in the following
definitions to the lazy evaluator:

(define count 0)
(define (id x) (set! count (+ count 1)) x)

Give the missing values in the following sequence of interactions, and explain
your answers.

(define w (id (id 10)))

;;; L-Eval input:
count

;;; L-Eval value:
⟨response⟩

;;; L-Eval input:
w

;;; L-Eval value:
⟨response⟩

;;; L-Eval input:
count

;;; L-Eval value:

⟨response⟩

练习 4.27:假设我们在惰性求值器中输入以下定义:

(define count 0)
(define (id x) (set! count (+ count 1)) x)

请给出以下交互序列中缺失的值,并解释你的答案。

(define w (id (id 10)))

;;; L-Eval input:
count

;;; L-Eval value:
⟨response⟩

;;; L-Eval input:
w

;;; L-Eval value:
⟨response⟩

;;; L-Eval input:
count

;;; L-Eval value:
⟨response⟩

Racket #lang sicp
(define count 0)
(define (id x) (set! count (+ count 1)) x)
Racket #lang sicp
(define w (id (id 10)))

;;; L-Eval input:
count

;;; L-Eval value:
⟨response⟩

;;; L-Eval input:
w

;;; L-Eval value:
⟨response⟩

;;; L-Eval input:
count

;;; L-Eval value:
⟨response⟩