Io, Day 1: Thoughts
We’ll start with the classic Hello World:
The way to think about this in Io terms is that you are passing the
message to the “Hello, World!” String object. I must note that having a space
between object and message makes the code noticeably harder for my mind to
parse. If the code had used a dot instead—
would’ve found it much easier! As it is, perhaps because I’m not used to it,
my comprehension is slowed and my aesthetic sense is tingling.
Here’s a simple example of defining variables and methods:
Method calls look similar to most languages I’m used to:
method param1, param2, .... However, I wonder if the Io way of looking at it is that the
speak method is an object and the phrase parameter is the message?
Finally, here’s an example that shows objects and prototypal inheritance:
In prototype-based languages, the distinction is blurred between a “class”—that is, some sort of template defining an object and its behavior—and an “instance” of that class. In Io, they are pretty much one and the same: you just clone an existing object to create a new one, whether you intend them as instances or templates.
The one place where “instances” do differ from “classes”, however, is by
convention: the class-like objects are usually named with an upper case first
Cat) while the instance-like objects are named with a lower case
first letter (
myCat). I suppose this sort of design greatly simplifies
the language, as there’s no need for special syntax, constructs, or rules for
Io, Day 1: Problems
The day 1 problems in this book are always very basic. I skipped a few of the really simple ones as they are not too interesting.
1 + 1 and then
1 + "1". Is Io weakly or strongly typed?
As you can see above, Io is a strongly typed language.
Dynamic code slot
Execute the code in a slot given its name.
System object contains various system properties and
methods. I pass the
args parameter to it to get the command line parameters.
I then use the
at method to access the parameter at a given index: in Io,
index 0 has the name of the app (
DynamicCodeSlot.io) and index 1 is the first
By calling the
getSlot method, I get back the object stored at the slot
named as a command line argument. Finally, the
call method does what you’d
expect: it calls that slot.
Continue on to Io, Day 2.