3 Modularity, Objects, and State
3.1 Assignment and Local State
3.1.1 Local State Variables
Exercise 3.1
(define (make-accumulator augend)
(lambda (addend)
(begin
(set! augend (+ augend addend))
augend)))
by iwk
Exercise 3.2
(define (make-monitored f)
(let ((count 0))
(define (how-many-calls?)
count)
(define (reset-count)
(set! count 0)
count)
(define (counting-procedure x)
(set! count (+ count 1))
(f x))
(define (dispatch m)
(cond ((eq? m 'how-many-calls?) (how-many-calls?))
((eq? m 'reset-count) (reset-count))
(else (counting-procedure m))))
dispatch))
by iwk
Exercise 3.3
(define (make-account balance passwd)
(define (withdraw amount)
(if (>= balance amount)
(begin
(set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (dispatch pass m)
(if (eq? pass passwd)
(cond ((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else (error "Unknown request -- MAKE-ACCOUNT"
m)))
(error "Incorrect password" pass)))
dispatch)
by iwk
Exercise 3.4
3.1.2 The Benefits of Introducing Assignment
Exercise 3.5
Exercise 3.6
3.1.3 The Costs of Introducing Assignment
Exercise 3.7
Exercise 3.8
3.2 The Environment Model of Evaluation
3.2.1 The Rules for Evaluation
3.2.2 Applying Simple Procedures
Exercise 3.9
3.2.3 Frames as the Repository of Local State
Exercise 3.10
3.2.4 Internal Definitions
Exercise 3.11
3.3 Modeling with Mutable Data
3.3.1 Mutable List Structure
Exercise 3.12
Exercise 3.13
Exercise 3.14
Exercise 3.15
Exercise 3.16
Exercise 3.17
Exercise 3.18
Exercise 3.19
Exercise 3.20
3.3.2 Representing Queues
Exercise 3.21
Exercise 3.22
Exercise 3.23
3.3.3 Representing Tables
Exercise 3.24
Exercise 3.25
Exercise 3.26
Exercise 3.27
3.3.4 A Simulator for Digital Circuits
Exercise 3.28
Exercise 3.29
Exercise 3.30
Exercise 3.31
Exercise 3.32
3.3.5 Propagation of Constraints
Exercise 3.33
Exercise 3.34
Exercise 3.35
Exercise 3.36
Exercise 3.37
3.4 Concurrency: Time Is of the Essence
3.4.1 The Nature of Time in Concurrent Systems
Exercise 3.38
3.4.2 Mechanisms for Controlling Concurrency
Exercise 3.39
Exercise 3.40
Exercise 3.41
Exercise 3.42
Exercise 3.43
Exercise 3.44
Exercise 3.45
Exercise 3.46
Exercise 3.47
Exercise 3.48
Exercise 3.49
最終更新:2008年04月23日 22:01