Appeared in:
March 2002
Influenced by:
Typing discipline:
File extensions:
Versions and implementations (Collapse all | Expand all):
Programming language

Io is a prototype-based scripting language.

Io was created by Steve Dekorte in March 2002. It was meant to be a self-education project, to combine best features of several languages and to be as lightweight as possible. It was influenced by the following languages:

  • Smalltalk — all entities, including “primitive” data types, are objects and interact by exchanging messages (would-be methods in typical object-oriented languages).
  • Self — prototype-based paradigm.
  • Lisp — the code is represented as a tree, modifiable at runtime.
  • Lua — lightweight scripting language, suited for embedding.

Elements of syntax:

Inline comments //
Non-nestable comments /* ... */
Case-sensitivity yes
Variable assignment varname := value
Grouping expressions ( ... )
Block ( ... )
Physical (shallow) equality ==
Physical (shallow) inequality !=
Comparison < > <= >=
Sequence ;
If - then if(condition, trueBlock)
If - then - else if(condition, trueBlock, falseBlock)
Loop forever loop(loopBody)
While condition do while(condition, loopBody)
For each value in a numeric range, 1 increment for(i,first,last,1,loopBody)
For each value in a numeric range, 1 decrement for(i,last,first,-1,loopBody)


Hello, World!:

Example for versions Io-2008-01-07

This program creates a symbol “Hello, World!” (a symbol is an immutable sequence) and sends it a println message (similar to calling println method in other languages).

"Hello, World!" println


Example for versions Io-2008-01-07

This example uses iterative factorial definition. Program output for large numbers looks in the following way:

12! = 479001600
13! = 6.227021e+009
14! = 8.717829e+010
15! = 1.307674e+012
16! = 2.092279e+013
F := 1;
   N print;
   "! = " print;
   F println;
   F := F * (N+1);

Fibonacci numbers:

Example for versions Io-2008-01-07

This example uses iterative definition of Fibonacci numbers. for loop misses fourth parameter which sets loop step — it defaults to 1, so no need to set it explicitly.

N0 := 0;
N1 := 1;
   N2 := N1+N0;
   N0 := N1;
   N1 := N2;
   N0 print;
   ", " print;
"..." println; 

Fibonacci numbers:

Example for versions Io-2008-01-07

This example uses Binet’s formula. Math functions are called by sending a message to the number which is an object as well.

g := (5 sqrt + 1) / 2;
   N := ((g pow(i)) - ((1-g) pow(i))) / (5 sqrt);
   N round print;
   ", " print;
"..." println; 

Quadratic equation:

Example for versions Io-2008-01-07

To output several pieces of data in one line, a simple trick is used: these pieces of data form a list, and then the list is concatenated using join command, and the result is printed as one string.

A := File standardInput readLine asNumber;
   "Not a quadratic equation." println;
B := File standardInput readLine asNumber;
C := File standardInput readLine asNumber;
D := B*B-4*A*C;
A2 := 2*A;
   list("x = ", (-B/A2) asString) println;
sqrtD := D abs sqrt;
   list("x1 = ", ((-B+sqrtD)/A2) asString) join println;
   list("x2 = ", ((-B-sqrtD)/A2) asString) join println,
   list("x1 = (", (-B/A2) asString, ", ", (sqrtD/A2) asString, ")") join println;
   list("x2 = (", (-B/A2) asString, ", ", (-sqrtD/A2) asString, ")") join println;


Example for versions Io-2008-01-07

This example shows char-by-char string processing. Note that at(i) returns ASCII-code of i-th character of the string, and slice(i,i+1) returns the character itself as a string of length 1. The check whether the character is a letter is done using ASCII-codes, and conversion to uppercase and string output — using string representation.

S := File standardInput readLine asLowercase;
lastSpace := 1;
for(i,0,(S size)-1,
   ascii := S at(i);
   letter := S slice(i,i+1);
   if(ascii>=97 and ascii<=122,
      if(lastSpace==1, letter := letter asUppercase);
      letter print;
      lastSpace := 0,
      lastSpace := 1;