🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[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 ```