本文主要是介绍sicp 习题2.30,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
(define (square-tree lst)(cond ((null? lst) nil)((not (pair? lst)) (square lst))(else (cons (square-tree (car lst)) (square-tree (cdr lst))))))
(define (square x) (* x x))
run:
> (square-tree (list 1 (list 2 (list 3 4) 5) (list 6 7)))
{mcons
1
{mcons
{mcons
4
{mcons {mcons 9 {mcons 16 '()}} {mcons 25 '()}}}
{mcons {mcons 36 {mcons 49 '()}} '()}}}
>
(define (square-tree tree)(map (lambda (sub-tree)(if (pair? sub-tree)(square-tree sub-tree)(square sub-tree)))tree))(define (square x) (* x x))
这篇关于sicp 习题2.30的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!