📜 ⬆️ ⬇️

Io programming language

In fact, when I defended my diploma, some free time was formed and I decided to get together and write about this wonderful little thing.
We have recently seen a surge of interest in all very high-level languages, with anonymous functions, currying, map / fold, metaprogramming and other blackjack. Thank God, I think.
The tasks become more complicated and if people use relatively low-level development tools, a situation often occurs when the set of abstractions is small within the framework of the problem being solved, something like “spaghetti” and bicycles appear. Good enough. Although I do not want to belittle the role of low-level programming, for obvious reasons.

More recently, in 2002, the brave American Steve Decorte realized that he somehow did not like everything around him. Well, that is, like, but somehow in parts. Like Smalltalk with its b-oop nature, like Lisp with its metaprogramming system and general megahizability, like Self with its prototypes, like Lua, because it's small and nicely embedded anywhere. But that would all at once - something is not right. The gallant American grieved, and nakolbasil own programming language - Io.

Io


Io is a small, completely object-oriented programming language with dynamic typing and an advanced metaprogramming system, anonymous functions, and the resulting buns. In addition, Io is incredibly simple, both in syntax and inside. There are only two entities: objects and messages. Everything else is built on this basis. In general, the whole language follows the Zen spirit of minimalism and simplicity.
In Io there is no concept class, only an object. The object can be cloned and modified, so we get another object (These are the prototypes). All data types, values, etc. are objects.
')
Here we go.

Io in examples


  "Hello world" print 

This is the very thing. Many (and me at the very beginning of my platonic relationship with Io) were greatly embarrassed, why the hell is print called so strange? Everything is simple, it is important to understand that there are no methods and properties in Io, there are slots and messages. In this example, the “Hello world” line sends a print message. In more traditional OOP languages, this would look something like this:
  "Hello world" .print () 

This is what would be easier to understand.

Now directly about the vaunted prototype OOP:
 Mushroom: = Object clone
 Mushroom isPoison: = false
 Mushroom whenEaten: = method (person,
   if (self isPoison == true 
     person kill
   ) 
 )

In this code snippet, we create a Mushroom object, define it as edible, and create the whenEaten method that kills the eater in case the fungus is poisonous.
 Man: = Object clone
 Man state: = "Living"
 Man eat: = method (food,
   food whenEaten (self)
 )
 Man kill: = method (
   self state: = "Dead"
 )

We define the object “Muzhyg”, as can be seen from the code, Muzyg can eat and die (well, something like that).
As Sergey Anatolyevich Kuryokhin proved - Lenin was a mushroom. Thus, we can define Lenin through cloning of the class Mushroom:
 Lenin: = Mushroom clone
 Lenin isPoison: = false
 Lenin speak: = method (
   "Patriotism is one of the most profound feelings 
    enshrined over centuries and millennia of separate fatherlands. "println 
 )

Also, for a change, you can determine the poisonous fungus:
 InfectedMushroom: = Mushroom clone
 InfectedMushroom isPoison: = true 

Now we can try to feed the man with something:
 Man eat (Mushroom)
 Man state println

Print “Living.”
 Man eat (InfectedMushroom)
 Man state println

Respectively "Dead"

At the time Lenin said:
 Lenin speak

A man came to eat it:
 Man eat (Lenin)

And he survived.

Metaprogramming


The metaprogramming system in Io is a thousand times simpler than in the same Lisp, but no less powerful. There is no “macro” concept here, just the entire code tree is available in runtime. No need for distortions with complex syntactic constructions, just change the “on fly” code as you like.
My favorite example is the implementation of Singleton in Io:
 Singleton: = Object clone
 Singleton clone: ​​= Singleton

Here I simply redefined the standard clone method, so that it returns the same object.

At last


Io is very young, but not over the years funny language. Despite its mega-bounce and power, it is extremely simple. The language itself is designed for ease of integration into alien systems; it is easy for it to write modules in low-level languages ​​when a performance is required. Enough libraries are already written for it.
There are several projects that actively use Io, for example, the It project is an Io-based scripting language developed by Pixar.
Now I am translating Io documentation into Russian. Of course, I touched on very little in this post, so to be continued (-;

Links


http://iolanguage.com

(From my blog )

upd: cycle continuation: Io syntax

Source: https://habr.com/ru/post/28041/


All Articles