CG@CPPBLOG

/*=========================================*/
随笔 - 76, 文章 - 39, 评论 - 137, 引用 - 0
数据加载中……

我的SICP习题答案(2.33~2.35)

2.33

(define (map+ p seque)
  (accumulate (lambda(x y) (cons (p x) y)) null seque))

(define (append seq1 seq2)
  (accumulate cons seq2 seq1))

(define (length seque)
  (accumulate (lambda(x y) (+ 
1 y)) 0 seque))

2.34

(define (horner-eval x coeff-seque)
  (accumulate (lambda(this-coeff higher-coeff) 
                (+ this-coeff (* x higher-coeff)))
              
0 coeff-seque))

2.35

(define (count-leaves+ t)
  (accumulate + 
0 (map (lambda(x)
                         (if (pair? x) (count-leaves+ x) 
1))
                       t)))


posted on 2008-06-24 00:21 cuigang 阅读(704) 评论(0)  编辑 收藏 引用 所属分类: Lisp/Scheme我的SICP答案


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理