多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ### 如何设计递归 例子 1 ``` ;由n个 hello构成的表 ;hellos:n->list-of-symbols ;预期值 ;(hellos 0) ;empty ;(hellos 1) ;(cons 'hello empty) ->(cons 'hello (hellos 0)) ;可以看出带有递归性 ; (hellos 2) ; (cons 'hello (cons 'hello empty)) -> (cons 'hello (hellos 1)) (define (hellos n) (cond [(= n 0) empty] [else (cons 'hello (hellos (- n 1)))])) (hellos 2) ;(list 'hello 'hello) ``` 例子 2 ``` ; 阶乘 ; 1!->1 ; 2!->1x2->1x1! ; 3!->1x2x3->3x2! ; n!->nx!(n-1) (define (! n) (cond [(= n 1) 1] [else (* n (! (- n 1))) ])) (! 1);1 (! 3);6 ```