第九章 复合数据类型
最后更新于:2022-04-02 04:14:18
[TOC]
## 9.5.2 例子
设计函数how-many-symbols,该函数读入一个符号表,返回表中元素的数目。设计函数how-many-numbers,该函数读入一个数表,返回表中元素的数目。思考-下 how-many-symbols和how- many-numbers有什么差别?
* how-many-symbols 解答
```
(define (how-many-symbols a-list-of-symbols)
(cond
[(empty? a-list-of-symbols) 0]
[(cons? a-list-of-symbols)
(+ 1 (how-many-symbols (rest a-list-of-symbols)))]
[else (error 'how-many-symbols "params is error")]))
(how-many-symbols (cons 'a (cons 'b empty))) ;2
```
* how-many-number 解答
```
(define (dollar-store? a-list-of-numbers)
(cond[(empty? a-list-of-numbers) true]
[else (cond
[(> (first a-list-of-numbers) 1) false]
[else (dollar-store? (rest a-list-of-numbers))])]))
(dollar-store? (cons 0.3 (cons .2 empty))) ;#t
```
';