现在的位置: 首页 > 综合 > 正文

simply scheme 第三章 练习

2013年12月08日 ⁄ 综合 ⁄ 共 1563字 ⁄ 字号 评论关闭

 

3.1 Translate the arithmetic expressions (3+4)×5 and 3+(4×5) into Scheme expressions, and into plumbing diagrams.

(× (+ 3 4) 5)     (+ 3 (× 4 5))

 

3.2 How many little people does Alonzo hire in evaluating each of the following expressions:

(+ 3 (* 4 5) (- 10 4)) (* (- (/ 8 2) 1) 5) 2)     6个

 

(* (+ (- 3 (/ 4 2)) (sin (* 3 2))(- 8 (sqrt 5))) (- (/ 2 3) 4)) 10个

 

3.3 Each of the expressions in the previous exercise is compound. How many subex- pressions (not including subexpressions of subexpressions) does each one have?

For example,

(* (- 1 (+ 3 4)) 8) has three subexpressions; you wouldn’t count (+ 3 4).

 

3.4 Five little people are hired in evaluating the following expression:

(+ (* 3 (- 4 7))(- 8 (- 3 5)))

 

Give each little person a name and list her specialty, the argument values she receives, her return value, and the name of the little person to whom she tells her result.

(+ (* 3 -3) (- 8 -2))=(+ -9 10)=1

 

3.5 Evaluate each of the following expressions using the result replacement technique:

(sqrt (+ 6 (* 5 2)))=4

(+ (+ (+ 1 2) 3) 4)=10


3.6 Draw a plumbing diagram for each of the following expressions:

(+ 3 4 5 6 7) (+ (+ 3 4) (+ 5 6 7)) (+ (+ 3 (+ 4 5) 6) 7)

自己画

 

3.7 What value is returned by (/ 1 3) in your version of Scheme? (Some Schemes return a decimal fraction like 0.33333, while others have exact fractional values like 1/3 built in.)

1/3

 

 

3.8 Which of the functions that you explored in Chapter 2 will accept variable numbers of arguments?

+ * operations

 

 

 

3.9 The expression (+ 8 2) has the value 10. It is a compound expression made up of three atoms. For this problem, write five other Scheme expressions whose values are also the number ten:

An atom 10

Another compound expression made up of three atoms (+ 1 9)

A compound expression made up of four atoms (+ 1 3 6)

A compound expression made up of an atom and two compound subexpressions (+ 1 (+ 1 2) (+ 1 5))

Any other kind of expression ...

 

 

 

 

抱歉!评论已关闭.