多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[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 ```