programmer things

Here is a very simple piece of code that could be from any number of programming languages:

X=somefunction(Expression);

An explanation of how this code is evaluated (assuming strict evaluation) might be something like this, “Expression is evaluated and then passed to somefunction. The value returned from the function is bound to X.” Right to left. This is unfortunate because we read from left to right. A few programming languages and environments treat left-to-right reading of code as an opportunity to structure the flow of data in a way that aids in comprehension and almost all have some tricks to simulate this in various ways, but none seem to fully embrace it in a practical way. I think we should.

Python 3 is easily the worst thing to happen to the Python community. I remember when I first used Python, I had been spending a lot of time in C++ land, and Python was like a revelation. I could open up a text editor and have a working program in seconds or minutes, not hours or days. I remember when Python 2.5 came out with a lot of neat new language features. I love Python, but I acknowledge that it has weaknesses, but that’s OK, all programming languages do. Its strengths are what make it interesting. While Python 3 has some tiny, incremental improvements over Python 2, it has lost many of Python 2’s strengths.

Disclaimer: This is Quicksort, just not one you’d use in
production. You can see it does twice as many comparisons as necessary,
or much worse if it encounters a pre-sorted list. The list manipulation
(via ++ or APPEND) is doing more work and using more memory than
necessary, even for a purely functional implementation.

Rob Pike did a great talk
at Google on concurrency in Newsqueak. The gist of it is that you spawn
concurrent tasks in separate lightweight processes and synchronize by
communicating through channels. That stuff worked its way into the
programming language Go. After seeing that video I wanted to try it out
myself in Common Lisp, of course. It turns out there is a
Quicklisp-installable library called
ChanL that provides just that
functionality. I don’t know how lightweight the threads are, but the
interface is similar.

0. Delayed Evaluation with Closures

Last week
I expressed some anti-lazy sentiment, or at least it was perceived as
such. Really, I am just not a fan of laziness by default. Common Lisp is
decidedly not lazy by default, but it is easy to defer or avoid
computation with closures. With macros, we can add it to the language in
an easy-to-use form.

0. The Rationale

Clojure, Scala, and Haskell (and other languages) have recently brought the
idea of immutable (and persistent) data structures into some amount of
popularity. This is not a new idea, by any means, as Lisp has always
supported this with its list structure, which is essentially a linked
list. In Common Lisp and Scheme, lists are actually mutable but in
practice, this is rarely a problem because it is generally considered
bad form to go around mutating lists except under certain circumstances.
Most Lisp books, tutorials and references encourage using lists in a
functional style (that is, assuming and treating them as immutable
structures).