Io (programming language)

from Wikipedia, the free encyclopedia

Io is a compact prototype-based , object-oriented programming language . The inventor and main developer, the American Steve Dekorte, attaches great importance to minimalism in the development, both in terms of code size and the complexity of the syntax and memory consumption. This is also reflected in the motto of the language Io - less is more . In Io more than in other programming languages: "Everything is an object". The language was mainly inspired by Smalltalk (all values ​​are objects), Self , NewtonScript , Act1 (prototype-based inheritance, actors and access), Lisp (code can be viewed and modified at runtime) and Lua (compact, embeddable).

Characteristic properties

What is particularly interesting about Io is the prototype-based approach of object-oriented programming , in which no classes are used. Instead, objects are assigned so-called prototypes. Methods or fields that do not exist are then automatically searched for in the prototype. An object is thus defined by the properties of its prototype and its specific differences in state and behavior compared to the prototype. This type of object-oriented programming is similar to that of JavaScript .

Another interesting property of Io is the use of so-called actors to achieve concurrency . An actor is, as it were, a “living” object; it is a lightweight thread that stores asynchronous method calls in a queue and then executes them one at a time. Synchronization problems can thus be circumvented elegantly. Such an asynchronous method call returns a transparent future as the result . This future blocks access until a value is actually available and then becomes the result.

Like other scripting languages , Io is translated into an abstract syntax tree (AST). The parser is written in C, an Io version is in development (November 2005). As a special feature, this AST consists exclusively of Messageobjects: Each of these objects represents one of the usual processes in OO languages ​​for sending a message to a recipient. This tree of news broadcasts can be inspected at runtime and, if necessary, manipulated. This makes it possible to write Lisp-like macros .

The message tree is interpreted by a simple virtual machine that only consists of around ten thousand lines of ISO-C code. The virtual machine provides incremental garbage collection (English garbage collection ) to support weak references ( weak references ). In addition to this minimal VM, expanded VMs are available with add-ons for the most important areas of application, including regular expressions , an XML parser, Blowfish encryption, and an OpenGL , PortAudio and FreeType binding. Supported platforms are currently Mac OS X , Linux , the BSD systems, IRIX , Windows , Symbian OS and L4 .

Io is under the BSD license .

Sample code

// Kommentare im C++-Stil können benutzt werden
# sowie Shell-Kommentare
/* und Kommentare im Stil von C */

"Hello world" print // Hello World

for(i, 1, 10, i print) // Gibt die Zahlen von 1 bis 10 aus

x := Object clone // Syntax wie in Smalltalk: ':=' erzeugt neue Slots
x = Map clone // '=' wird zum überschreiben benutzt
x prettyprint := method( // Erstellt eine Methode ohne Argumente
    foreach(key, value, write(key, ": ", value, "\n")) // Schleife über 'map'
)
x atPut("hi", 1) // Schlüssel-Wert-Paar in 'map' schreiben
x atPut("hello", 2)
x prettyprint
/* Ausgabe:
     hi: 1
     hello: 2
*/

Web links