Io language notes²²Io is a small, well-designed and efficient scripting language created in²2002 by Steve Dekorte. Io is particularily pleasant because it has a rather²clean, regular syntax that frees us from the ugly C-style braces and²trailing semicolos, pretty much like an hybrid of Python and Lisp.²²Io also introduces some interesting perspectives and features, notably by²providing asynchronous execution primitives that really ease the²development of concurrent applications -- these primitives are indeed based²on the actor languages paradigm.²²Io language main site is available at http://www.iolanguage.com, Steve's²page at http://www.dekorte.com. There is also the main Io wiki available at²http://io.kicks-ass.net/FrontPage.²²Related pages:²²* IoObjcBridge?, introduces the bridge that allows cross-integration of Io²* and²Objective-C.²* IoQa?, questions and answers that came on the Io mailing list IoCuts?, a²* collection of Io code snippets that I gathered on the Io mailing list.²* IoModuleSystem, a draft for a module/package system for Io²* IoDocumentationSystem, a draft for a documentation system for Io²* PurelyObjectOriented?, a discussion on purely object-oriented languages²* that²originated from a discussion I had on the Io ML.²²!! 1. A quick glance at Io²²Here is an Object-oriented Hello World in Io:²² HelloObject?? = Object clone HelloObject?? sayHello = method( "Hello World!"² print ) HelloObject?? sayHello()²²You can check out some more Io examples at²http://www.iolanguage.com/SampleCode.html.²²----²²!! 2. Io language traits²²Now that the impatient was fed with some source code, I will introduce Io²from a more theorical point of view and expose the traits (a.k.a. the²language features) that make it such a pleasant beast:²²* Prototype-based: Io object model does not uses classes but instead clones²"prototype" objects, which stand as a model on which to base every²"instance".²²* Purely Object-Oriented: all entities that are manipulated in Io derive from the same Object prototype.²²* Garbage-collected: objects are automatically allocated and deallocated.²²* Weakly typed: although Io has a notion of type, variables are untyped and operations prototypes do not carry type information. Some type checks can be madeusing generally available methods.²²* Interpreted: Io source code is not compiled to bytecode but rather read and²converted to an in-memory representation.²²* Code as data: blocks of code are reified into objects, which can be modified and dynamically created.²²* Reflective: as a consequence of the "code as data", it is possible to investigate the properties of any Io object at runtime, including its source code.²²* Dynamic: because code is data (and vice-versa), it is possible to change a program logic during its execution.²²Although Io shares some traits with functional languages, Io could be²considered as a memeber of the imperative family of languages. However, Io²dynamicity and deep reflexivity enables programming styles that are not²usually possible with other languages from the imperative family.²²I consider Io as a very interesting language for scripting existing²applications, though I would rather advice the use of a statically,²strongly typed language for the application core. Io has a simple syntax,²is very flexible and powerful, but lacks some features of more mature²languages, such as Python:²²* Io does not offer a module/package system Extensions (coded in C) cannot be dynamically loaded (for x-platform compatibility) There is no javadoc-like tool There are no exceptions There are no type-checking/object utilities (like interfaces)²²Io is constently evoloving, and Steve is rather open to comments, as proved²the improvement of the VM toward a single-rooted object hierarchy²(primitives used to inherit from IoValue??, and Object was a primitive).²²-----²²!! 3. Io object model²²Io is a purely object-oriented language...²²Definition of a message Prototype based Values, Primitives and Objects²Mechanisms involved in responsing to a message Messaging model²²Io has the very appreciable feature of accessing the object that sent a²message to the receiving object. This allows to modify the behaviour of the²receiving object according to the type of the invoking object. The sender²object is accessible using the "sender" slot of the receiving object.²²²----²²!! 4. Understanding Io concepts²²Io is based on some concepts that may not be familiar to people used to²common programming languages such as C, C++ or Java. At first, Io is²inspired by the following kinds of languages:²²* Prototype-based language: languages that realise inheritance by cloning object rather than instanciating them from a class.²* Actor language: languages that consider objects to be dynamic and to communicate with messages²* Functional languages: languages that provide a lambda-like operator, either closure or blocks.²²Don't be afraid if you don't know the languages or understand my short²presentation, this will be explained here.²²!!! A. Types and Protoypes²²Even if types and prototypes share the same "types" suffix, they both²represent different things. A type qualifies and categories a given value,²while a prototype is already a value.²²Most programming languages allow to define new types ; in object-oriented²programming, new types are defined with classes. Classes can be considered²as a model that will be reproduced by the instances, the reproduction of²the model is done by the class constructor operations. The main problem²with classes is that they may not be referencable or accessible (if the²language is not reflexive like C++, unlike Java), and that it is definitely²not possible to modify them at runtime.²²Prototypes allow to do the same as defining new types through classes:²instead of describing a class, we construct an object that will serve as²the actual model for future "instances". The equivalent operation to²creating an instance is simply to "clone" the prototype. This language²trait allow to freely manipulate prototype, which is not always possible²with classes (though a fully reflexive non-prototype language would²certainly exhibit the same features).²²The idea behind prototypes (which could also be called "stereotype") is²that you build a collection of predefined objects that will serve as a²basis for all object that will be based on them. Prototype is a very²interesting way to weave objets together.²²A good thing would also be to have a look at this page [1].²²Links:²* [1] Prototype-based languages definition in WikiPedia??,²http://www.wikipedia.org/wiki/Prototype_based²²!!! B. Types and Tags²²Tag in Io are inspired from Lua typing system [2], a tag specifies a given²type. For instance, a Lua function could be either implemented in Lua or in²C. To make the difference between both functions (which are considered as²first-class language citizens, ie. values) the tag is used to indicate²wether the function is in C or in Lua. Tags can then be considered as a²sub-type.²²Tags are useful for customising Io because they allow to extend or redefine²the behaviour of a specific type, like for instance redefine how a list²would react the add or remove messages.²²Steve gives the following explaination on tags :²²Every value is a primitive of some sort - a String, List, Objects, etc. And²the data structure for each primitive begins with "mark" and "tag" members.²Example:²² typedef struct { IoMark? mark; Tag *tag; ByteArray? *byteArray; }² IoString?;²²The mark is for gargabe collection purposes and the tag is a reference the²primitive's tag datastructure. The tag is used to figure out which C²function to call for a given operation on a value. For example, when the²garbage collector decides to free the IoString??, it ends up looking in the²IoString??'s tag and finds the freeFunc function pointer and calls it. This²function pointer is set to IoString?_free. The freeFunc function pointer in²a tag for a different primitive would would be set to a different C²function. This makes it easier for people to externally add new primit²²Links:²²* [2] See Lua 4.http://www.lua.org/manual/4.0/manual.html manual in²* sections 3 and 4,²at http://www.lua.org/manual/4.0/manual.html. They provide a great²explaination on how tags can be used.²²!!! C. Reflectivity²²Io is an intrinsically open language, as it offer very powerful reflexive²features. One of the interesting features is that Io stores the whole²program as a tree that mirrors the source code. This tree is not compiled²to bytecode, but is rather directly executed.²²One of the side effects of this choice is that you can get the source code²at anytime. For instance, any Io object can output its source code. This²is a truely interesting feature from an open-source development²perspective, which recalls me the power of categories in ObjectiveCee?.²²!!! D. Language constructs reification²²The combination of tags and reflexivity grants Io with very powerful²self-modifications features, such as redefining the behaviour of executing²a block value. Here is a Io code snippet that substitutes the default block²activation function with a new one:²² IoTag? *tag = IoState?_tagWithInitFunction_(ioState,² StateTagInit?*)IoBlock?_initTagWithId_); tag->activationFunc =² MyBlockActivationFunc?;²²then in the activation function, you can do what you want:²² IoValue? * MyBlockActivationFunc?(IoBlock? *self, IoObject? *target,² IoObject? *locals, IoMessage? *m) {² /* Do what I want */² /* And call the normal IoBlock? activation function */² IoBlock?_target_locals_call_(self, target, locals, m); }²²[ Note that this example was given by Steve on the Io mailing-list]²²I'm not sure if this is the right term for qualifying this, but to me,²language reification means that the language internal mechanism is reifeide²so as to be able to reprogram the language with the language itself (or²through the use of simple extensions in C).²²!!2. Io terminology²²To have a better understanding of the different terms encountered in Io²documentation and in the Io mailing list, here is a short list of terms²with their accompanying definition:²²* Prototype: ...²* Slot:...²* Actor:...²* Asynchronous message:...²* Continuation:...²* Scope:...²* Tag:... ²* Untyped:... ²* Reflectivity:...²²See http://www.wikipedia.org/wiki/Dynamic_typing²