(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)
SICP Exercise 2.20+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.