Scheme as a Prototyping Language

The other day I saw a link to this short essay on using Scheme as a prototyping language by Jonathan Sobel. The TL;DR is that Sobel was taking an Algorithms class and was assigned a project to implement the fast multiplication algorithm with part of the grade based on fast it ran.

Most of Sobel’s classmates started writing in C. A few of them went directly to assembly language. They spent a lot of time debugging their highly optimized C and assembly code. Sobel pursued a different track; he started writing in Scheme. He began with a naive implementation of the algorithm and iteratively refined it.

Scheme is ideal for this. The language allows one to make correctness-preserving transformations to the code that eliminates function calls and allowed the caching of execution context. Once Sobel had his Scheme implementation optimized, he translated the code into C.

The results were impressive. Sobel’s implementation was the second fastest in the class, beaten only by an implementation written predominantly in assembly language. Sobel says that if he’d known a bit more about Scheme, his implementation would have come in first.

For almost all projects, I find writing in some sort of Lisp gets the job quickly, more accurately, and with a result efficient enough for a final product. In those rare cases where more speed is needed, Sobel’s strategy of writing in a Lisp, debugging and optimizing the program, and finally translating into C is a good strategy.

This entry was posted in Programming and tagged , . Bookmark the permalink.