Vincent Costel

Reading SICP

Published in 1985, Structure and Interpretation of Computer Programs (SICP) is a famous textbook that was formerly used to teach programming at MIT.

The programming language used in the book is Scheme, a dialect of Lisp, which make it a good way to learn and grasp functional programming.

Reading this book has been in my "sharpen the saw" to-do list for a while and I finally decided to give it a try. Given the fact that I only have a few hours a week to devote to this, it could take me many months to complete. So I committed to spend 25 hours to get started and see where this leads me.

This site has the book available in HTML format but I prefer using the epub version of this beautiful edition available on GitHub.

In order to run the code samples and to do the exercises, I installed Racket, a programming language in the Lisp-Scheme family. The Racket install comes with DrRacket, an IDE for writing Racket programs.

I open DrRacket and iBooks side by side in order to run the code found in the book and do the exercises:


So far I'm enjoying this. Let's see how far I go.

Here is a solution to the latest exercise I did, about computing Pascal's triangle values (ex 1.12).

  #lang racket

; Exercise 1.12
; Write a procedure that computes elements of
; Pascal’s triangle by means of a recursive process.

(define (pascal r c)
(cond ((= c 1) 1)
((= c r) 1)
(else (+ (pascal (- r 1) (- c 1)) (pascal (- r 1) c)))))

; Testing
(pascal 1 1)
(pascal 2 1)
(pascal 2 2)
(pascal 3 1)
(pascal 3 2)
(pascal 3 3)
(pascal 4 1)
(pascal 4 2)
(pascal 4 3)
(pascal 4 4)
(pascal 5 1)
(pascal 5 2)
(pascal 5 3)
(pascal 5 4)
(pascal 5 5)