hw5 - ; Exercise 2.24 ; (1 (2 (3 4) ; Exercise 2.26 ;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
; ;; Exercise 2.24 ; (1 (2 (3 4))) ; ;; Exercise 2.26 ; (define x (list 1 2 3)) ; (define y (list 4 5 6)) ; ; (append x y) returns (1 2 3 4 5 6) ; (cons x y) returns ((1 2 3) 4 5 6) ; (list x y) returns ((1 2 3) (4 5 6)) r ;; Exercise 2.29 ; (define (make-mobile left right) (list left right)) (define (make-branch length structure) (list length structure)) (define (left-branch mobile) (car mobile)) (define (right-branch mobile) (cdr mobile)) (define (branch-length branch) (car branch)) (define (branch-structure branch) (cdr branch)) ( (define (total-weight mobile) (+ (branch-length (left-branch mobile)) (branch-length (right-branch mobile)))) ( (define (balanced? mobile) (if (equal? (branch-length (left-branch mobile)) (branch-length (right-branch mobile))) '#t '#f)) ' ;; If you change list to cons in the original definition of make-mobile and make- branch, ;; then I wouldn't have to change anything in my code, because I only used car and cdr. c ;; Exercise 2.30 ; (define (square x) (* x x))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/30/2010 for the course EECS 21281 taught by Professor Harvey during the Spring '10 term at University of California, Berkeley.

Page1 / 3

hw5 - ; Exercise 2.24 ; (1 (2 (3 4) ; Exercise 2.26 ;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online