Seven Languages, Week 2: Io

The second week in the “Seven Languages in Seven Weeks” book explores a more unusual terrain, namely Io. Io is, for lack of a better word different and while I had some things to complain about the minimal docs I have to admit that I kinda love the language. Well, probably more as a plaything because it is missing a bit to much for everyday use.

Io is object-oriented to a point that I have never seen in other languages before to a point where things like method calls do not exist and the recipient object only sees a message which he can parse however he wants. In other words: the parameters of a method call do not have to be evaluated necessarily, which means you can implement nifty things like your own control flow statements.

One thing that I really like about Io is the syntax. It is simple, regular and reminds me a lot of Lisp (which is why I indent similar to Lisp). I think it is a good deal preferable to what JavaScript provides and while at this, it is vastly more powerful.

I’m not completely sold on the syntactic extension abilities (similar to Scala 2.8 and probably Ruby), each syntactic extension seems like a hack by combining a lot of orthogonal hooks together to just work which seems kind of “by accident”, as every possible syntactic extension needs to be thought of before to add the hooks to the Io implementation. Overall, this is the least impressive part, especially as defining operators does not work in the current parsing unit, so you can’t define a new syntax in a file and immediately use it. Kinda sad and the workaround (execute your extended code with doString/doFile/doRelativeFile) looks ugly.

I’ll give you an example which is pretty awesome yet demonstrates one of my complaints about the syntactic extension facilities of Io:

So we define a method squareBrackets that creates a list l, evaluates all of its arguments (1 is 1, 3+1 is 4) and appends the results to l which gets returned. squareBrackers is called when Io sees [], so this thing works. Really nice and cool but what if you want to use some other character like % or Å. There is no Åbrackets. What if you want the dividers to be something different than , maybe ; as in OCaml? You are out of luck because now you need to edit Io and add these hooks to the language. This is why I am only partly impressed with the “macros” if you like to call it this.

At the end of this week, a short critique of the Seven Languages-book: while I do like the topics that are presented and the ideas that get presented, the code is sometimes quite awful. Extending this code is often painful and the result looks quite ugly (if it is even possible). I got stuck in the XML formatter task, extending it to take an optional Map as first argument, first because of the afore-mentioned parser weirdness which makes using the newly introduced syntax tedious and second because the code uses writeln which makes it impossible to evaluate an argument without printing it immediately.

As for a random observation, I use vim to write the code and while the Ruby plugin was pretty awesome, the Io plugin I used was less so. We fought about our ideas of indentation and it gave up when I defined my own syntax (this is not entirely surprising of course).

Another funny observation is that Io’s killer app is the “Seven Languages in Seven Weeks” book. If you check out GitHub’s stats on Io you’ll notice that many repositories recently created or modified are repositories for hosting code of the book, just like I do :-)

Well, that’s it with Io. Overall I liked this week quite a bit more than previous week because it was way more of a challenge. Next week is Prolog, which will be a good deal more of a challenge. Oh well.