« May 2006 | Main | October 2006 »
June 22, 2006
Two good articles on LISP
I came across two good articles on The Nature of LISP and Functional Programming on www.defmacro.org. Both articles are excellent. They are very clear and informative and explain LISP and functional programming concepts in terms familiar to Java or C programmers.
Posted by JohnC at 09:53 PM
June 10, 2006
Scheming
I have started learning Scheme for fun and (hopefully) profit. I have been learning from a number of sources. Firstly, I have after learning the basics, I wrote another program to calculate the digits of π. The code is here (pretty printed). The algorithm I used is the same as the one I used for the python program and the two programs look very similar. I haven't yet learned how to code up closures in Scheme, so the method of calculating the Fibonacci terms to use is different, but apart from that they are pretty much the same.
Secondly, I found a few good online resources:
- The Structure and Interpretation of Computer Programs: This book is used as the textbook for MIT's famous course 6.001. It is an excellent book that very quickly shows its reader how to solve interesting problems using Scheme. For example, before the first chapter is finished, programs to evaluate derivatives of functions at a point, to calculate integrals, and a few methods of calculating square roots, have been discussed. This book is a classic and is also known as the Wizard Book. I bought paper copy: it really is that much of a classic.
- MIT Open Courseware for 6.001. I found this via a good article on the O'Reilly Network site, entitled Learn Lisp From MIT—for Free!!!
- Teach Yourself Scheme in Fixnum Days: This book gives a very good introduction to the syntax and structure of Scheme and is a handy reference.
- The schemers.org website.
I use Kawa and SISC as scheme interpreters. Both of these run on top of the Java VM and are easy to use and fit in well on UNIX/Linux systems. Running on top of the Java VM opens up some possibilities such as using the Java VM Dtrace probes to observe Scheme programs. I am not sure how well this will work, but it is something I will be investigating.
Why am I learning Scheme? Well, there are a few reasons. I really admire Paul Graham's essays and his essays on LISP and strong advocacy piqued my interest in the language. I also came across an essay describing design patterns supported by LISP. Many of the patterns I use regularly in Java programs, such as the Visitor pattern, Command pattern, and Iterator pattern, are not needed in LISP: they are built in at the language level. Because of this, I wanted to learn more and, although I have just started, I am sure this is going to make me a better programmer.
Posted by JohnC at 07:57 PM
Irish OpenSolaris Users Group Meeting
There will be a meeting of the Irish OpenSolaris Users Group in the SUN offices in Dublin next Wednesday. The full details are on Tim's blog. If you intend on coming along, drop Tim a mail. Hopefully, I will see you there.
Posted by JohnC at 05:02 PM
June 08, 2006
Readable code
I had an, "Aha!", moment yesterday, regarding source code readability. I followed a link from Tim Bray's blog, to an analysis by Josh Bloch of a bug in the Java binary search code. In summary, the bug was caused by an overflow in an integer calculation. While reading the explanation of the problem and its solution I realized I had read something like it before and, after a few minutes thinking, I realized it was in the code of Metafont. I had read this in Donald Knuth's book, Literate Programming, a few months earlier. In particular, it was from section 108 of Metafont and the text in question was:
Notice that the computation specifies
(p - q) + pinstead of(p + p) - qbecause the latter could overflow. Let us hope that optimizing compilers do not miss this point; a special variablebe_carefulis used to emphasize the order of computation.
Now when I was reading this I was not studying the code: I was just idly reading it. However, the insight into variable overflow stayed with me. Perhaps it was because the program was written in the literate programming style and, therefore, was explicitly written to be as readable as possible, that I remembered. If so, reading literate programs is a subtly powerful technique for programmer training.
Posted by JohnC at 11:54 PM