Seven Languages in Seven Weeks – Io – Day 1

Tuesday, January 18, 2011

My quest to learn seven languages in seven weeks continues. Next language that I am tackling is Io. By this time I am now very well aware, that due to the fact that I don’t have much time for private life lately, I will probably end up spending seven months for the task as mentioned in my previous post. In order to make some visible progress, I decided to blog about my endeavours on a day by day rather than language by language basis.

So let me sum up my thought after day one with Io. You might not heard about this language before as it is not as popular or well known as others mentioned in the book. Io is an object oriented prototype language. This means that it doesn’t have the notion of a class as an object template meaning that there is no distinction between classes and instances – all object are merely clones of other objects. The language is very simple and syntax is minimal. Objects are created by cloning like this:

Food := Object clone

As mentioned the language is not very widespread hence no syntax highlighting. Objects are nothing more than a collections of “slots”. Slots can hold values or methods both of which are objects and this is how slots are created:

Food description := "Something to eat"
Food eat := method("Yum!" println)

First line defines a “description” slot that holds a value and second line defines an “eat” slot that holds a method. When message is passed to an object object is checked whether it contains a slot with that name. If it does it will either return a value or invoke the method held in the slot. If it doesn’t, then its protoype (object it was cloned from) and its prototypes are search for the matching slot and that one gets invoked if it exists. Otherwise an exception gets raised. This means that if we clone Food object to create pizza and define description and shape slots we get following behaviour:

Pizza := Food clone
Pizza description := "Flat bread with toppings"
Pizza shape := "Round"

Io> Pizza description
==> Flat bread with toppings
Io> Pizza shape
==> Round
Io> Pizza eat
==> Yum!

What I find very amusing about this is that we can change slots and prototypes at run time, which shows the malleability of language and makes it feel like working with putty. For instance let’s assume Pizza is also a programming language (which is an unorthodox but not a completely insane idea). Not a problem – new ProgrammingLanguage object needs to be cloned and it has to be added to list of Pizza’s prototypes.

ProgrammingLanguage := Object clone
ProgrammingLanguage description := "Something to use for programming"
ProgrammingLanguage paradigm := "generics, algebraic types"
ProgrammingLanguage eat := "It's silly to try to eat a language"

Pizza appendProto(ProgrammingLanguage)

Io> Pizza description
==> Flat bread with toppings
Io> Pizza paradigm
==> generics, algebraic types
Io> Pizza eat
==> Yum!

We have just proven of Io’s flexibility and at the same time seen how it deals with multiple inheritance. If an object does not have a slot that would respond to the message passed to it, it will search it’s prototypes using depth first algorithm. That’s why Pizza will search it’s own slots when trying to respond to a message, if it can’t find a match it will try Food’s slots. If it can’t find a match there either, it will search Food’s prototype – Object. After it has gone full depth on first prototype (Food) and it still hasn’t found an appropriate slot, it will try the next prototype (if present), which in our case is ProgrammingLanguage. And so on… This is how “paradigm” message gets resolved on Pizza object in our example.

“Homework” is really simple at the end of the first day with Io. Probably due to the fact that it is not completely trivial to install.

First task is to run an Io program from a file. Which is just the same as running a ruby script. If you write your application in a file called, you can run it like this:


It is also possible to make script executable on *nix systems by marking file as executable and adding a shebang to the top of the file like so:

#!/usr/bin/env io

"Hello Cruel World!" println

Second task is executing the code in a slot given its name. It’s almost easier done than said. ;)

Io> Pizza perform("description")
==> Flat bread with toppings

Thus far I am very impressed by Io. Exploring it just brings a smirk on my cheeks and what I’ve seen so far makes me quite excited at the prospect of finding out what’s next on its agenda. I think having that much fun, must be worth something, even if I might never get to do anything productive with the language.

Well I hope on day 2 Io will show more of its tricks…


  1. Very interesting subject , appreciate it for posting . “The great leaders have always stage-managed their effects.” by Charles De Gaulle.

Leave a Reply

Pingbacks & Trackbacks

  1. Dalibor Novak » Seven Languages in Seven Weeks – Io – Day 3 - Pingback on 2011/03/06