Computer Science Canada [Io] Let's party OOP-style! |
Author: | wtd [ Sat Nov 11, 2006 5:19 pm ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
Post subject: | [Io] Let's party OOP-style! | ||||||||||||||||||||||||||||||||||||||||||||||||||
What are these object things?
That's an object.
That's an object too. As is:
Everything's an object! But objects have methods, right? Darn straight!
And that just returns another object, so we can call a method on that.
But what's really going on here? Well...
Sends the "factorial" message to the object 4. In response, the method in the "factorial" slot of the target object is called. We can, of course, put a new method in that slot.
What about binary methods?
Which are really just messages which take one argument.
So, what about methods which take multiple arguments?
Let's write a method.
As it happens, "method" is just a message being sent to Object. And here it's taking a single argument. But if "method" is a method... how in the name of everything unholy does it do what it does?
This should immediately be evaluated, and the value submitted to "method". But really, it's a Message object, and if we want, we can evaluate it at any time. This is how things like "method" work. It's also how things like conditionals and loops work.
So, let's write a method that takes an argument.
There's nothing especially phenomenal about that. But really, that's the same as:
So, sayHello is now a method of Object. And since every other object has Object as a prototype...
Isn't that neat? ![]() We can even see that Object is a prototype of 4.
So, obviously 4 doesn't itself have a slot to answer to the sayHello message. Since it doesn't, it looks for a way to respond to that message in its prototypes. It finds one in Object. We can add other prototypes to an object.
So let's look at something else.
Now, we can create a name. We just have to clone Name, and give that new object's first and last slots updated values.
And since bobsName has the Name object as a prototype, and Name has the Object object as a prototype, then it has a println method.
And this naturally prints:
But, what if I want it to print:
Well, I'd need for bobsName to have a title slot. That's easy enough.
But it's still going to print "Bob Smith" because when this object answers the asString message, it ends up looking for fullName. It finds this in the Name object, but that fullName method doesn't know about title. The fullName method in the FormalName object does, though. So we just need to make that object a prototype of bobsName.
|
Author: | wtd [ Sun Nov 12, 2006 6:11 pm ] | ||
Post subject: | |||
A little more Io code to contemplate. An RPN calculator.
|
Author: | wtd [ Tue Nov 14, 2006 1:53 pm ] | ||
Post subject: | |||
|
Author: | wtd [ Fri Nov 17, 2006 2:39 pm ] |
Post subject: | |
A native Windows build. Thanks to rdrake for the link. http://www.nabble.com/Native-Io-binary-for-win32-available-for-download-t2441272.html |