Io Day 2

My experience with day two of exploring Io through Seven Languages in Seven Weeks.

Day 2 of Io follows a pretty similar format to Ruby day 2 looking at conditional loops, operators and reflection.

Conditional Loops

Conditional Loops in Io are not pretty to read. It’s basic syntax means it is easy to remember how to write conditional loops but it takes a bit of concentration to read the code and get what it is doing. I miss a bit of Ruby’s syntactic sugar!

Io allows you to attach additional parameters but it is up to you to make sure your arguments match correctly. If you miss a parameter your arguments end up in the wrong place, there is no compiler to babysit you. The example below shows the optional increment parameter and prints only odd numbers.


One thing I really like about Io is the ability to create your own operators which allows you to build some very succinct and powerful syntax. The following command displays the operators and their precedence.

You can add your own operators and specify their precedence.

If you want to see a full example of this take a look at my day 3 post


Almost everything in Io is a message. You can query any characteristic of a message and act on it appropriately. The key components are the sender who sends the message, the target who received and executes the message and the message arguments.


Here is a simple example of object reflection printing out the ancestors of an object and their slots.


A Fibonacci sequence starts with two 1s. Each subsequent number is the sum of the two numbers that came before: 1, 1, 2, 3, 5, 8, 13, 21, and so on. Write a program to find the nth Fibonacci number. fib(1) is 1, and fib(4) is 3. As a bonus, solve the problem with recursion and with loops.

How would you change / to return 0 if the denominator is zero?

Write a program to add up all of the numbers in a two-dimensional array.

Add a slot called myAverage to a list that computes the average of all the numbers in a list. What happens if there are no numbers in a list? (Bonus: Raise an Io exception if any item in the list is not a number.)

Write a prototype for a two-dimensional list. The dim(x, y) method should allocate a list of y lists that are x elements long. set(x, y, value) should set a value, and get(x, y) should return that value.

Bonus: Write a transpose method so that (new_matrix get(y, x)) == matrix get(x,y) on the original list.

Write the matrix to a file, and read a matrix from a file.

Write a program that gives you ten tries to guess a random number from 1 to 100.

Check out my code at github