`
frenchmay
  • 浏览: 229022 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

SICP Exercise 2.20+

 
阅读更多
(define x (list (list 1 2) (list 3 4)))
x
(car (cdr x))
(car  x)

(define (deep-reverse items)
  (display items)
  (newline)
  (cond 
      ((null? items) ())
      (( not (pair? items)) items)
      ( (pair? items) 
        (list (deep-reverse (car (cdr items))) 
            (deep-reverse (car items))
            )
       )
    )
  )

(deep-reverse x)


(define x (list (list 1 2) (list 3 4)))

(define (fringe items)
  (cond 
    ((null? items) ())
    ((not (pair? items)) (list items) )
    (else
     (append  (fringe (car items)) (fringe (car (cdr items))))
     )
    )
  )
  
 (fringe x)
 
 
(define (left-branch items)
  (car (car (cdr items)))
  )

(define (right-branch items)
  (car (cdr (car (cdr items))))
  )

(define (branch-length items)
  (car items)
  )
(define (branch-structure items)
  (car (cdr items))
  )
(branch-length x)
(branch-structure x)
(left-branch x)
(right-branch x)


(define (total-weight items)
  (cond 
    ((not (pair? items)) 0)
    (else (+ (branch-length items) (+ (branch-length (left-branch items)) (branch-length(right-branch items))) ))
    )
  )
(total-weight z)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics