2015/09/08 21:47

# 练习3-8

## 原文

Exercise 3.8. When we defined the evaluation model in section 1.1.3, we said that the first step in evaluating an expression is to evaluate its subexpressions. But we never specified the order in which the subexpressions should be evaluated (e.g., left to right or right to left). When we introduce assignment, the order in which the arguments to a procedure are evaluated can make a difference to the result. Define a simple procedure f such that evaluating

(+ (f 0) (f 1)) 

will return 0 if the arguments to + are evaluated from left to right but will return 1 if the arguments are evaluated from right to left.

## 分析

(+ (f 0) (f 1)) 

## 代码

(define f (lambda (first-value) (set! f (lambda (second-valua) 0)) first-value))
;Value: 

## 测试

(define f (lambda (first-value) (set! f (lambda (second-valua) 0)) first-value))
;Value: f

(+ (f 0) (f 1))
;Value: 1

(+ (f 1) (f 0))
;Value: 0

## 总结

(lambda (second-value) 0)

(f 1)
;Value: 1

(f 1)
;Value: 0

(f 1)
;Value: 0

(f 1)
;Value: 0

(define m 2)
;Value: m

(f m)
;Value: 0

m
;Value: 2

# 练习3-7

## 原文

Exercise 3.7. Consider the bank account objects created by make-account, with the password modification described in exercise 3.3. Suppose that our banking system requires the ability to make joint accounts. Define a procedure make-joint that accomplishes this. Make-joint should take three arguments. The first is a password-protected account. The second argument must match the password with which the account was defined in order for the make-joint operation to proceed. The third argument is a new password. Make-joint is to create an additional access to the original account using the new password. For example, if peter-acc is a bank account with password open-sesame, then

(define paul-acc (make-joint peter-acc 'open-sesame 'rosebud))

will allow one to make transactions on peter-acc using the name paul-acc and the password rosebud. You may wish to modify your solution to exercise 3.3 to accommodate this new feature.

## 分析

make-joint需要有3个参数：
1.有密码保护的帐户名
2.必须与账号的密码匹配的原密码
3.新密码

## 代码

(define (make-joint origin-acc old-password new-password)

(define (display-wrong-message msg)

display-wrong-message)))
;Value: make-joint

http://blog.csdn.net/nomasp

0
0 收藏

0 评论
0 收藏
0