ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
### **[下载](https://racket-lang.org/download/)** 一、在Lisp方言Scheme里,给事物命名通过**define**(定义)的方式完成,输入: ``` >(define size 2) ``` 会导致解释器将 size 跟 2关联 ***** ### **二、复合过程** 1.定义一个复合过程 ``` >(define (square x) (* x x)) ``` 这样我们就有了一个复合过程,名字为**square**(求一个数x的平方) **过程定义**的一般形式为: ``` >(define (<name > <formal parameters>) <body>) ``` 2.使用这个复合过程 ``` >(square 21) 441 ``` 3.定义 x² + y² ``` >(+ (square x) (square y)) ``` 4.定义一个过程求两个数的平方和 ``` >(define (sum-of-squares x y) (+ (square x) (square y))) ``` ***** ### **三、条件表达式** 1.求一数绝对值 ``` >(define (abs x) (cond ((> x 0) x) ((= x 0) x) ((< x 0) - x))) >(define (abd x) (cond ((< x 0) (- x)) (else x))) >(define (abf x) (if (< x 0) (- x) x)) ``` 2.求三个数之间较大两个数的和 ``` >(define (ac x y z) (cond ((and (> x y) (> y z)) (+ x y)) ((and (> x z) (> z y)) (+ x z)) ((and (> y x) (> x z)) (+ y x)) ((and (> y z) (> z x)) (+ y z)) ((and (> z x) (> x y)) (+ z x)) ((and (> z y) (> y x)) (+ z y)) )) (ac 2 5 3) ``` 3.求幂 b 的n次方 ``` (define (expt b n) (if (= n 0) 1 (* b (expt b (- n 1))))) (expt 3 3) ```