The language for this week is Io, a prototype-based language. The language embraces minimalism, down to the documentation (which is really terse).
Anyway, this week is about Io. As stated above, it is a prototype-based language (meaning there is no difference between class and object), with a simple and regular message passing syntax and semantic.
Today’s exercises explore various basic aspects of the language.
Io is typed
Trying to evaluate
generates an error:
1 2 3
The error message in this case is fairly clear and verbose, fortunately.
0 and the empty strings are both true, while
nil is false:
1 2 3 4 5 6
Slots in an object
slotNames gives the list of slots:
Difference between =, := and ::=
Each operator is mapped to a method:
The difference between
setSlot is simple:
setSlot creates and set the value of a slot, whereas
updateSlot only updates the value of an existing slot.
newSlot is the same as
setSlot, but it creates a setter method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Execute the code in a slot given its name
getSlot method returns the value for the named slot. Apparently if the value is a method, this calls the method as well, if there are no arguments (otherwise the method object is returned):
1 2 3 4 5 6
Wrapping up day 1
So Io has a minimal and consistent syntax. The objects can be easily introspected, and the operators are mapped to methods which can be redefined.