Really this is just a convention that helps with certain design patterns. So porsche is an instance of Car, and it has no defined slots. This might not seem useful, but by the power of prototypal inheritance, porsche gets all the behaviors of Car, Vehicle, and Object.
In addition to normal slots, objects have a slot called Protos , which stores a List an array containing all of the prototypes the objects inherit state and behaviors from. Because this is a list, Io supports multiple inheritance, and the "prototypal inheritance chain" is actually not a chain, but a tree.
When an object receives a message, it checks it's local slots for a match. If there isn't one, it triggers a depth first search searching ancestor prototypes for a match.
The first match found receives and processes the message. This logic for performing a depth first search lives in the forward method of the base Object prototype. The simple architecture of message passing and prototypal inheritance is quite powerful. In fact, just about the entire Io language is implemented as methods on prototypes.
For example, the base Object prototype stores methods at the slots for and if , so branching and looping works via objects and message passing just like everything else.
This works because the global namespace of Io's execution environment is the Lobby object, which has Object in its prototype chain. The Lobby is the default target for messages when none are explicitly specified, which is how something like the following works:. We've learned that messages are passed to objects and handled by matching slots, and that these slots can exist anywhere in the prototypal inheritance tree.
Let's take a closer look at messages themselves. In fact, when we talk about messages, we are really talking about two things: the message and the call. In the context of mailing a letter, the message is like the letter. It has "Dear John" indicating the name of the person that the message is for and the main content of the message the arguments. The call is like the envelope.
It wraps the message and has an address and a return address to help the postman with delivery. Let's illustrate this by a simple example. KITT can talk via the method say, but what would the message have to look like for this to work? Inside of the receiving method, the call and the wrapped message can be inspected as follows:.
The second call we sent to KITT doesn't find a local drive slot, so it traverses the prototypal inheritance chain to the Car Prototype. Given that calls and messages are just normal objects, they provide slots with states and methods. The examples above are just the basics, but the technique provides a powerful tool for message reflection without having to know advanced syntax.
In Io, methods are anonymous functions that are stored at slots. They are defined by the method method , which exists as a slot on the base Object prototype. The last expression of the block is implicitly returned. In this example, we don't explicitly declare an Object, so it is added as a slot on the Lobby object, which constitutes the global namespace. When invoked, a method creates a locals object, which is used to store all local variables.
So when we call porsche drive , we are sending a message with the name drive to the target porsche. Even though this delegates up to the Vehicle prototype, in the locals object self is set to porsche. Because Io is designed around messages that get passed to receivers, concurrency ends up being quite simple. Prefixing a message with returns a future. Prefixing a message with dispatches the message to execute on a separate thread. Given that the entire language and standard library is implemented using the same basic concepts as end-user applications, Io is extremely simple to customize and extend.
This makes it well suited to metaprogramming and Domain-Specific Languages. Or I can take this further and shadow the forward method used for prototypal inheritance and create a compiler that allows me to define DOM nodes using a LISP like syntax:. The source code for these examples can be found in this GitHub repo. Io is like a s Volkswagen Beetle. It's designed by an enthusiast and optimized to allow other enthusiasts to get under the hood and tinker. This is a breath of fresh air considering many larger languages are like modern luxury cars that can only be serviced by licensed technicians.
Working with Io taught me that a language doesn't need much syntax when the underlying design is strong. Objects and message passing are powerful, and the language is an absolute blast to learn. So while Io has not achieved mainstream success, I think that's fine. It's pleasurable to work with and rewards the programmer with all sorts of insights along the way. I've never built a programming language, but I share Steve's interests and have done a bit of research on resources for learning about interpreters and compilers.
For those academically-minded, the Dragon book seems to be the dominant academic textbook in the space. Once CMake has finished preparing the build environment, ensure you are inside the build folder, and run:. Finally, install Eerie , the Io package manager see Eerie repo for installation options :. Io can then be run with the io command and Eerie can be run with the eerie command. We want to do an out-of-source build, so: mkdir buildroot and cd buildroot.
Install Eerie , the Io package manager see Eerie repo for installation options :. Note: If you also have CMake 2. You should be inside your out-of-source build dir. The vm tests can be run with the command:. Many of the common features provided by the Io language aren't prepackaged in the Io core. Instead, these features are contained in addons that get loaded when launching the Io VM. In the past, these addons were automatically installed by the build process, but now they must be installed through Eerie , the Io package manager.
To ensure that an addon installed correctly, pull up an Io interpreter and type the name of the object provided by the addon. It should load dynamically and automatically into the interpreter session, populating a slot in Lobby Protos Addons.
Skip to content. Star 2. Io programming language. View license. Branches Tags. Could not load branches. Could not load tags.
0コメント