July 8, 2012 IoLanguage, Languages
July 8, 2012 IoLanguage, Languages
I would expect that most of you never heard about such programming language as Io. Very likely programmers would associate Io with “input-output”, but Io language has nothing special to do with it and has no cool in-out features.
Io is extremely tiny language which runs on supermall virtual machine, even your micro-oven can handle. Having that said I don’t mean that Io is not powerful.
Io is prototypical object-oriented language with dynamic typing. For me, as C# guy, it was not easy to “feel” the language. I could very quickly understand syntaxes and mechanisms of language. It will not take for you longer than 20 minutes to start writing simple code, either. I was understanding what I was trying out, but I didn’t feel myself comfortable with realizing that anything can be changed in this language on the fly which could affect all of the prototypes of changed object. Note that there is no difference between class and object, or better to say, there are no classes in Io. If you define method on some object it is ultimately inherited to the clones. It worth to mention that in Io every operation is message. “Hello world” application which would look like:
Should be understood like: “send message “println” to the string object”.
Here is bit more code (sheep example cloned from this post):
Sheep := Object clone Sheep legCount := 4 MutantSheep := Sheep clone MutantSheep legCount = 7 dolly := MutantSheep clone MutantSheep growMoreLegs := method(n, legCount = legCount + n) dolly growMoreLegs(2)
The coolest thing about Io is its concurrency model, at least I think so.
Io uses coroutines, actors, yielding and future stuff. If you don’t know what it is about. Here is a bit of explanation. Coroutines in Io are user threads, built on top of kernel threads, which allows for quick switching of contexts and more flexibility in general. For simplicity think about coroutines as about threads. Any object can be sent message asynchronously, by adding @ symbol before the message name. This message is then places in object’s message queue for processing. Object would hold coroutine (thread) for processing those messages. Objects holding coroutine are called Actors. Effectively any object in Io can become Actor. When you call some methods asynchronously, result can be saved into so called “future”, value of which is resolved before it is used. You can switch between actors using “yield”. To demonstrate this, I prepared this small piece of code, which prints numbers 0,1,2,3 one by one:
oddPrinter := Object clone evenPrinter := Object clone oddPrinter print := method(1 println; yield; 3 println; ) evenPrinter print := method(0 println; yield; 2 println; yield) oddPrinter @print; evenPrinter @print;
If you found this to be interesting I recommend you to read Io Guide. There you will find many other interesting features of the Io language, which I didn’t mention.
Here are some links:
You may be wondering why I’m writing and learning something about old, small language, which even doesn’t have normal ecosystem.
I’m trying to learn more programming concepts and play with different languages. Recently I was even blamed for writing “enterprise-y code” and suggested to see how code looks like in other programming language communities. Well… of course it is valid and good suggestion, but not that I never thought about it. In my year plan post I mentioned that I would like to learn one more programming language and to start with something I picked up interesting book called “7 languages in 7 weeks”. So far I read and tried Ruby, Io and Prolog. Scala, Erlang, Clojure and Haskell are next in a row. After I’m done with book I will pick one language (not compulsory from list) and extend my knowledge in it. Of course there will be a review on the book.
Markdown | Result |
---|---|
*text* | text |
**text** | text |
***text*** | text |
`code` | code |
~~~ more code ~~~~ |
more code |
[Link](https://www.example.com) | Link |
* Listitem |
|
> Quote | Quote |
I have been plaing with it.
Now i am write small apps on clojure
Looking forward to play with Clojure as well. Thanks.
Would you advice me to reed this book ?
Well… You left comment as Anonymous.
Anyway it always depends on your needs. If you are interested to quickly go through couple of interesting languages I would recommend this book. Though book is not always easy to follow. Also when you read always do home work :)
If you want deep insight into one-two languages or comprehensive explanations or step-by-step samples this book is not your choice.
Thank you for reply on my previous question
Also i want to thank you for interesting(as for me) blog and especially for ukrainian book about design patterns. I am going to register on PayPal and donate a few dollars for it though i didn't download or read this book yet. It's just because i like indifferent people, which don't do something only for their own profit, but for other people too.
So good luck
Thank you for the kind words.