I don’t know where to start…
First of all, I must say that this is one of the most interesting books on programming I’ve ever read. (and yes, I haven’t read so many books on programming, for now) In the last few days I constantly go to bed around 3:00 am, (it’s 1:30 am, as I’m writing this). I’m getting worried, that I may end up in an asylum, muttering „cadr“, „cdadr“, „cddar“, and so on, which the doctors will take for some kind of ill-spoken obscenities, and will put me to sleep with… Wait, what? Yes, it’s that worse. 🙂
I’ll start the sensible part of this post with my „infrastructure changes“, which I made during the last week. I’m finally using tests! I used this library, and switched to GNU Guile as a Scheme implementation. This shouldn’t be a problem, since I’m not using anything specific. I should mention that Guile tends to have somewhat tight constraints on it’s stack size, since I encountered twice „STACK OVERFLOW“, when I tried to run recursive versions of „sum“ and „accumulate“ with larger volumes of data. The iterative implementations work fine, but I will search for a way to increase the stack size.
One of the ways the tests show their usefulness is that they remove the testing from the source file with the solution, leaving much more clean code there. The other one is the easier refactoring, of course. It’s a win-win all the way, so I recommend them to anyone, that has at some previous experience with Scheme. I also wrote a simple Emacs LISP after-save-hook, that runs the tests (if any) for an exercise after each save. I also tried to abstract it as a separate function, that could be attached to a key combination, and I failed, but I’ll launch another offensive on my Emacs soon. 🙂
And for the tiny list of interesting stuff, that can be found in the exercises of Chapter 2:
cdrcan all be expressed as simple procedures, as shown in ex. 2.4. Stefan showed a problem here – how can we define
pair?to work with this implementation?
- I knew from before, that we can encode pairs of positive integers with positive integers (ex. 2.5), but is was fun to do a simple implementation of the idea in Scheme. It reminded me of the university course of Computability and Complexity, where we used this idea to encode programs for Registers Machines with single numbers. (like, the number (228234 + 217532) can represent a program, that takes two numbers and finds their average.) It was one of the most interesting courses I’ve ever attended. 🙂
- If the previous two where not enough, you get Church Numerals (ex. 2.6). I’m curious how one can implement comparison of Church numerals.
- Practically all the exercises in 2.2.3 were very contenting, although most of them were „fill the missing function in the slots“, it was like learning to ride a bicycle, with stabilizing wheels. 🙂
There are other interesting things, of course, but I’m tired and it 2:30 AM now. So, as a compensation, here is a link with resources on Scheme – http://www.math.bas.bg/bantchev/place/scheme.html The entire site is worth checking, if you are interested in programming languages and have free time.
Happy Scheming! 🙂