SICP

This is an archive of the practice exercises and assignments that I worked on while reading through The Structure and Interpretation of Computer Programs. I started out doing every single exercise and quickly got bored, so now I tend to pick and choose.

Most of my solutions to the first chapter exercises were dumped into a latex doc, but starting with section 1.3.1 the problems definitely became more code-focused and so I’m going to start with just posting source files.

Also, from 2.32 onwards, I leaned on my own libraries in the exercises, so you’ll need to load these beforehand if you want to execute any of the procedures in the solutions. The libraries are all prefixed with “debo-” :)

Exercises

Libraries

Assignments

Blackjack

This assignment involved writing some HOFs to implement blackjack strategies. The “tutorial exercises”, which were significantly more demanding than the assignment questions, involved changing the implementation of hands, decks, etc to use a concrete data structure (a list), and then modifying the supplied game code to work with a concrete deck implementation. Since the second half of the assignment involved modifying the supplied code, I did that part in a separate file.

I had to do a wee bit of porting to make the supplied code work in PLT Scheme, but it wasn’t anything too complex, or I probably wouldn’t have been able to figure it out.

Finally, I didn’t really feel like writing a bunch of list splitting, mapping, and reducing functions all over again, so I used the SRFI/1 list.ss library. Some really cool stuff in there! My favorite discovery was unfold, which essentially a HOF that implements many of the things you’d expect a list comprehension to be able to do.

There was some awkwardness involved in moving a discrete deck around the program because every time you draw from an immutable deck, you need to also return the mutated deck itself. Instead of making two function calls or taking the cdr of the deck every time, I took advantage of Scheme’s values and let*-values, that essentially let you return multiple values from a function and bind them in one let statement. For the record, I find this kind of thing much easier to do in both Python and ML, where you can just stick a bunch of symbols in a tuple on the LHS, like let (a, b, c) = my_three_values () in a + b + c.

Curve drawing

This assignment depended on a whole whack of weirdo code written in MIT scheme. I didn’t feel like switching to MIT scheme at this point, nor did I really feel like porting the whole thing, so I just bailed on most of it.

Comments (0)

› No comments yet.

Leave a Reply

Pingbacks (0)

› No pingbacks yet.