Starting Io
Well I am back to reading Seven Languages in Seven Days by Bruce Tate and am taking on the chapter on Io. If you are not familiar, Io is a prototype-based language like JavaScript. Since I typically work on the server-side and only dabble in JavaScript and HTML, I am looking forward to seeing how learning Io can reflect on my knowledge of JavaScript.
The first thing to grab my attention is how slots on clones are handled. You’ll notice that the Car created from the Vehicle clone does not have a description slot listed when the slotNames message is sent to it. Also, Tate indicates that when you send the description message to Car, the message is forwarded to the prototype, Vehicle. Let’s see how that shakes out:
Io 20110905 |
Interesting, changing the description slot on Vehicle is reflected when the description message is sent to Car. But apparently it can be overridden:
Io> Car description = "Something else entirely" |
Interestingly you can use the weaker = assignment even though in one sense the description slot had not been defined on Car.
Here’s another question: can we clone non-types and what is the behavior? In turns out the behavior is pretty much the same, except that the prototype is listed as the prototype of the cloned object:
Io> anotherFerrari := ferrari clone |
Moving on to the exercises, most are straightforward. However, following my nose lead me to an interesting place when trying to execute the code in a slot given its name.
Io 20110905 |
Initially I tried to get to the code via getSlot. While this worked, I ended up with a Block and then tried sending the call message to it. The code was executed, but the right thing was not returned. Somehow I ended up with the Lobby being returned instead of x. It turned out the better approach was to use the perform method on Object. Now the correct value is returned.