devNoo

musings of a Software Developer

Seven languages in seven weeks : My solutions for Io day 2

| 0 comments

In day 2 of the Io chapter I got a much clearer view of what Io was, and how you could use it.
There are a bunch of exercises, here are my solutions.

Exercise 1

Fibonaci generator with recursive calls:


Fibonaci generator with a loop:

The recursive solution is a lot slower than the one with the loop, I was surprised to notice this with only 25 loops.

Overloading the division operator

In Fact you just have to overload it in the number class.

Sum two dimensional array

I went a bit further than only summing a 2d array. This code sums a multidimensional arrays that consists of inner arrays or numbers.

Implement myAverage on list
The exercise is to implement a average method on list that will return the average of all numbers in the list, and throws an exception if an element is not a number:

Implementing all exercises dealing with the matrix

Guess number game
Assignment: Code a guess the number game for a number under 100.

I’m really getting to love the simplicity of Io. I had to get used to the syntax and the mechanism of prototyping, but it is quite powerful. Only thing I dislike till now, is the fact that formatting/outlining code is quite hard, because you kind of inline every code block. I prefer the way Java and other languages deal with blocks vs method calls so { vs (, because often you forget a bracket somewhere and in Io it can be quite hard to find the problem.

Leave a Reply

Required fields are marked *.

*