The Viamentis Blog

Curious About Everything

The Viamentis Blog header image 2

Exploring SICP

April 30th, 2006 · Posted by Vamsee · 5 Comments

This book totally rocks. And it kinda makes me depressed. Some exercises are really tough, and it’s putting me through all kinds of grief. But heck, I’m getting a kick out of learning this stuff. Kinda like going back to college and getting all the stuff right. But you need to have a lot of patience. You need to unlearn some concepts. Anyways, to console myself, I have done one of the easier exercises (1.8). Here’s how you calculate a cube root (apologies to non-geeks – the posts in the coming days/weeks would be full of this):

(define (cuberoot-iter guess x)
  (if (good-enough? guess x)
      guess
      (cuberoot-iter (improve guess x)
             x)))

(define (improve guess x)
  (/ (+ (/ x (square guess)) (* 2 guess)) 3))

(define (good-enough? guess x)
  (< (abs (- (cubed guess) x)) 0.001))

(define (cubed x)
  (* x (* x x)))

(define (cuberoot x)
  (cuberoot-iter 1.0 x))

Evals to (using mit-scheme):

(cuberoot 27)
;Value: 3.0000005410641766

Tags:

5 responses so far ↓

  • 1 Ankur // Apr 1, 2006 at 9:09 am

    yuck … i’ll never put myself thru this torture … hats off to ur efforts ne ways …

  • 2 Sidharth Kuruvila // Apr 1, 2006 at 9:09 am

    Sicp is a pretty heavy read, I did give it a shot many years ago, didnt get very far. The exercise are definitely worth doing.

    I’m currently reading Concepts Techniques and Models of Computer Programming(CTM) its another introductory text on computer programming on very different lines, it uses a rather interesting language called Oz.

  • 3 Sidharth Kuruvila // Apr 1, 2006 at 9:09 am

    Btw I think you might find this interesting, it’s a simple scheme interpreter I wrote some time ago in python.

    <a href=”http://thinkpython.blogspot.com/2005/02/simple-scheme-interpreter.html” rel=”nofollow”>scheme.py</a>

  • 4 Startups.in // Apr 1, 2006 at 9:09 am

    So, I guess you’d really come out as a Computer Scientist once you are through that book. :)

    G’luck.
    Nag @
    Startups.in

  • 5 Vamsee // Apr 1, 2006 at 9:09 am

    Hmm. I hope so. I can’t really call myself a computer scientist… just a developer who’s discovering the cool languages out there. Scheme certainly seems interesting, and I would love to dig deeper. Hope to find some more time to spend on it!

Leave a Comment