Monthly Archives: April 2012

SICP solution for exercise 2.9

Solution for exercise 2.9 of SICP: (define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y)))) (define (mul-interval x y) (let ((p1 (* (lower-bound x) (lower-bound y))) (p2 (* (lower-bound x) (upper-bound y))) (p3 (* … Continue reading

Posted in SICP | Tagged , | Leave a comment

SICP solution for exercise 2.8

Solution for exercise 2.8 of SICP: (define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y)))) (define (mul-interval x y) (let ((p1 (* (lower-bound x) (lower-bound y))) (p2 (* (lower-bound x) (upper-bound y))) (p3 (* … Continue reading

Posted in SICP | Tagged , | Leave a comment

SICP solution exercise 2.7

Solution for exercise 2.7 of SICP: (define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y)))) (define (mul-interval x y) (let ((p1 (* (lower-bound x) (lower-bound y))) (p2 (* (lower-bound x) (upper-bound y))) (p3 (* … Continue reading

Posted in SICP | Tagged , | Leave a comment

SICP solution exercise 2.6

Solution for exercise 2.6 of SICP: ; Define one and two directly (not in terms of zero and add-1). ; (Hint: Use substitution to evaluate (add-1 zero)). ; ; Give a direct definition of the addition procedure + ; (not … Continue reading

Posted in SICP | Tagged , | Leave a comment

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

Posted in SICP | Tagged , | Leave a comment

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

Posted in SICP | Tagged , | Leave a comment

SICP solution exercise 2.3

Solution for exercise 2.3 of SICP: ; Representation 1 of rect: ; As a pair of rect’s diagonal’s end-points. ; rectangle abstraction (define (perimeter r) (* (+ (base r) (height r)) 2)) (define (area r) (* (base r) (height r))) … Continue reading

Posted in SICP | Tagged , | Leave a comment

SICP solution exercise 2.2

Solution for exercise 2.2 of SICP: ; segment abstraction (define (midpoint-segment s) (midpoint (start-segment s) (end-segment s))) ; point abstraction (define (midpoint p q) (make-point (/ (+ (x-point p) (x-point q)) 2) (/ (+ (y-point p) (y-point q)) 2))) (define … Continue reading

Posted in SICP | Tagged , | Leave a comment

SICP solution exercise 2.1

Solution exercise 2.1 of SICP: (define (make-rat n d) (let ((g (gcd n d)) (s (if (negative? (/ n d)) -1 1))) (cons (/ (* s (abs n)) g) (/ (abs d) g)))) (define r (make-rat 1 -4))

Posted in SICP | Tagged , | Leave a comment

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

Posted in SICP | Tagged , | Leave a comment