SICP学习笔记(1):

[0]:学会了基本使用scheme命令行和基本表达式:

(1)第一个代码文本里面,用前缀表达式来定义计算.

;The first program

(define x (+ (* 3 (+(* 2 4) (+ 3 5))) (+(- 10 7) 6)))
(define A (* x x))

(2)定义过程:

一般形式:(define ((name formal parameters)(body))

(define (square x) (* x x))
(define (add x1 x2) (+ x1 x2))
(define (sub x1 x2) (- x1 x2))
(define (div x1 x2) (/ x1 x2))

定义一个复合过程:

(define (f a) (+ (square (+ a 1)) (square (* a 2))))

运用条件判断:

(define (abs x) (if(< x 0) (- x) x))

练习1.2:将(5+4+(2-(3-(6+4/5))))/(3(6-2)(2-7))变换为前缀表达式:

(define s (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7))))

练习1.3 求出3个参数中较大两个数的和:

注意应该考虑相等的特殊情况

(define (max_add x y z) (if(and (<= x y) (<= x z)) (+ (* y y) (* z z)) (max_add y z x) );processure body )

练习1.5:

#define (p) (p)
#(define (test x y)
 (if (=  x 0 ) 0 y))
(test 0 (p))

请说明在不同求值顺序的情况下出现的情况:

[1]:正则求序,直接得到0,因为这种情况下test被直接展开,然后根本不会调用(p)

[2]:应用求序,先求出各个子表达式的值,这样就会陷入无限递归.

你可能感兴趣的:(SICP学习笔记(1):)