企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[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 ```