
Recent Posts
Archives
Categories
Monthly Archives: April 2012
SICP solution for exercise 2.9
Solution for exercise 2.9 of SICP: (define (addinterval x y) (makeinterval (+ (lowerbound x) (lowerbound y)) (+ (upperbound x) (upperbound y)))) (define (mulinterval x y) (let ((p1 (* (lowerbound x) (lowerbound y))) (p2 (* (lowerbound x) (upperbound y))) (p3 (* … Continue reading
SICP solution for exercise 2.8
Solution for exercise 2.8 of SICP: (define (addinterval x y) (makeinterval (+ (lowerbound x) (lowerbound y)) (+ (upperbound x) (upperbound y)))) (define (mulinterval x y) (let ((p1 (* (lowerbound x) (lowerbound y))) (p2 (* (lowerbound x) (upperbound y))) (p3 (* … Continue reading
SICP solution exercise 2.7
Solution for exercise 2.7 of SICP: (define (addinterval x y) (makeinterval (+ (lowerbound x) (lowerbound y)) (+ (upperbound x) (upperbound y)))) (define (mulinterval x y) (let ((p1 (* (lowerbound x) (lowerbound y))) (p2 (* (lowerbound x) (upperbound y))) (p3 (* … Continue reading
SICP solution exercise 2.6
Solution for exercise 2.6 of SICP: ; Define one and two directly (not in terms of zero and add1). ; (Hint: Use substitution to evaluate (add1 zero)). ; ; Give a direct definition of the addition procedure + ; (not … Continue reading
SICP solution exercise 2.5
Solution for exercise 2.5 of SICP: (define (cons a b) (* (expt 2 a) (expt 3 b))) (define (car c) (if (> (modulo c 2) 0) 0 (+ (car (/ c 2)) 1))) (define (cdr c) (if (> (modulo c … Continue reading
SICP solution exercise 2.4
Solution for exercise 2.4 of SICP: (define (cons x y) (lambda (m) (m x y))) (define (car z) (z (lambda (p q) p))) (define (cdr z) (z (lambda (p q) q))) ; test (car (cons 3 4)) (cdr (cons 3 … Continue reading
SICP solution exercise 2.3
Solution for exercise 2.3 of SICP: ; Representation 1 of rect: ; As a pair of rect’s diagonal’s endpoints. ; rectangle abstraction (define (perimeter r) (* (+ (base r) (height r)) 2)) (define (area r) (* (base r) (height r))) … Continue reading
SICP solution exercise 2.2
Solution for exercise 2.2 of SICP: ; segment abstraction (define (midpointsegment s) (midpoint (startsegment s) (endsegment s))) ; point abstraction (define (midpoint p q) (makepoint (/ (+ (xpoint p) (xpoint q)) 2) (/ (+ (ypoint p) (ypoint q)) 2))) (define … Continue reading
SICP solution exercise 2.1
Solution exercise 2.1 of SICP: (define (makerat n d) (let ((g (gcd n d)) (s (if (negative? (/ n d)) 1 1))) (cons (/ (* s (abs n)) g) (/ (abs d) g)))) (define r (makerat 1 4))
SICP solution exercise 1.34
Solution for ex 1.34 of SICP: Evaluating (f f) We get: ;The object 2 is not applicable. ;To continue, call RESTART with an option number: ; (RESTART 2) => Specify a procedure to use in its place. ; (RESTART 1) … Continue reading