I have been studying Structure and Interpretation of Computer Programs for about one and an half months now. As everyone familiar with the book will know, at least half of the work (and the knowledge!) is in its several exercises. I started documenting my progress, writing down all solutions, but wasn’t sure whether I wanted to post them here. At first I wasn’t even sure I’d actually go through with the book, but as I’m reaching section 2.2.4 I am amazed by it and not intending to stop soon. Still, this doesn’t mean I’ll make it to the end, and I’m not stressing about how long it will take. I’m here for the long haul. It also goes without saying that you shouldn’t believe everyhting you read: some of these solutions might be incomplete or just plain wrong. Also usually I compare my notes to Eli Bendersky’s, he has done an amazing job documenting his progress and certainly inspired me.
On a slightly practical note: I have been using Racket with its SICP collection for the exercises. I considered using Clojure (which I’m already familiar with) but decided against it, mainly because I wanted to follow the text as closely as I could. Scheme is a very syntactically simple language and it is no coincidence the authors chose it to teach programming.
There are various solutions for the SICP exercises on the web, but these are mine.
if statement is evaluated, the operatior is chosen based on whether
b is positive or negative, and results into calculating
a + |b|.
Using applicative-order evaluation the evaluation never terminates, because as it is trying to evaluate the operands, the algorithm falls into an infinite loop.
Using normal-order evaluation, the algorithm does not try to evaluate
until it actually needs it. However, the computation terminates before that, as
if special form evaluates the first branch and returns