Io (programming language)#Examples
{{Short description|Prototype-based programming language}}
{{Multiple issues|
{{More citations needed|date=August 2014}}
{{Primary sources|date=August 2014}}
}}
{{Infobox programming language
| name = Io
| logo = Io-logo.svg
| logo_size = 150px
| paradigms = object-oriented prototype-based
| designer = Steve Dekorte
| developers = Steve Dekorte, Jonathan Wright, Jeremy Tregunna
| released = {{Start date and age|2002}}
| latest release version = 20170906
| latest release date = {{Start date and age|2017|09|06}}{{cite web |url=https://github.com/IoLanguage/io/releases |title=Io Releases |website=GitHub |access-date=2020-02-06}}
| latest preview version = 2019.05.22-alpha
| latest preview date = {{Start date and age|2019|05|22}}
| platform = IA-32, x86-64; ARM; .NET CLR
| operating system = Windows, macOS
| license = BSD 3-clause
| implementations = [http://iolanguage.org/ Io] [https://web.archive.org/web/20110716175739/http://synrc.com/io/index.htm Io.NET]
| influenced by = Smalltalk, NewtonScript, Self, Lua, Lisp, Python, Act1
| influenced = Ioke, Potion
}}
Io is a pure object-oriented programming language inspired by Smalltalk, Self, Lua, Lisp, Act1, and NewtonScript.[http://iolanguage.org/guide/guide.html#Introduction-Overview Io Programming Guide] Io has a prototype-based object model similar to those in Self and NewtonScript, eliminating the distinction between instance and class. Like Smalltalk, everything is an object and it uses dynamic typing. Like Lisp, programs are just data trees. Io uses actors for concurrency.
Remarkable features of Io are its minimal size and openness to using external code resources.{{Cite web |title=Io Programming: Writing Addons |url=https://en.wikibooks.org/wiki/Io_Programming/Writing_Addons |access-date=2023-06-22 |website=Wikibooks.org: open books for an open world |language=en}} Io is executed by a small, portable virtual machine.
History
Philosophy
Io's goal is to explore conceptual unification and dynamic languages, so the tradeoffs tend to favor simplicity and flexibility over performance.
Features
- Pure object-oriented based on prototypes
- Code-as-data, homoiconic
- Lazy evaluation of function parameters
- Higher-order functions
- Introspection, reflection and metaprogramming
- Actor-based concurrency
- Coroutines
- Exception handling
- Incremental garbage collecting supporting weak links
- Highly portable
- Shared library, dynamic-link library (DLL), dynamic loading on most platforms
- Small virtual machine
Syntax
{{Unreferenced section|date=June 2013}}
In its simplest form, Io syntax is composed of one identifier:{{Cite web |title=io guide |url=https://iolanguage.org/guide/guide.html#Syntax |access-date=2023-06-22 |website=iolanguage.org}}
doStuff
Assuming the above doStuff is a method, it is being called with zero arguments and as a result, explicit parentheses are not required.
If doStuff had arguments, it would look like this:
doStuff(42)
Io is a message passing language, and since everything in Io is a message (excluding comments), each message is sent to a receiver. The above example demonstrates this well, but not fully. To describe this point better, let's look at the next example:
System version
The above example demonstrates message passing in Io; the "version" message is sent to the "System" object.
Operators are a special case where the syntax is not as cut-and-dried as the above examples. The Io parser intercepts a set of operators defined by the interpreter, and translates them to method calls. For example, the following:
1 + 5 * 8 + 1
translates to:
1 +(5 *(8)) +(1)
All operators in Io are methods; the fact that they do not require explicit parentheses is a convenience. As you can see, there is also a little bit of operator precedence happening here, and the precedence levels are the same as with the C precedence levels.
= Methods and blocks =
In Io there are two ways of creating anonymous functions: methods and blocks. Between them, they are almost identical except for scope. While blocks have lexical scope, methods have dynamic scope.
Both method and block are higher-order functions.
= Examples =
The ubiquitous Hello world program:
"Hello, world!" println
New objects are created by cloning objects. In Io specifically, a new, empty object is created and only the differences between it and its parent are stored within the new object; this behavior is known as differential inheritance. An example of this behavior is shown:
A := Object clone // creates a new, empty object named "A"
A simple non-recursive factorial function, in Io:
factorial := method(n,
if(n == 0, return 1)
res := 1
Range 1 to(n) foreach(i, res = res * i)
)
Because assignment of res * i
to res
is the last action taken, the function implicitly returns the result and so an explicit return expression is not needed. The above demonstrates the usage of ranges, and doesn't use a for()
loop, which would be faster.
References
{{Reflist|refs=
{{cite book |last=Tate |first=Bruce |year=2010 |title=Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages |location=Raleigh, North Carolina |chapter=Chapter 3: Io |publisher=Pragmatic Bookshelf |page=[https://archive.org/details/sevenlanguagesin00tate/page/60 60, 72] |isbn=978-1934356593 |edition=1st |chapter-url-access=registration |chapter-url=https://archive.org/details/sevenlanguagesin00tate/page/60}}
}}
External links
- {{Official website|iolanguage.org}}
- {{GitHub|IoLanguage|Io}}
- [https://web.archive.org/web/20121012010044/http://synrc.com/research/io/index.htm Io at Synrc Research Center]
- {{GitHub|bekkopen/jasmineio|Jasmine.Io}}, Behavior Driven Development (BDD) testing framework for Io
{{DEFAULTSORT:Io (Programming Language)}}
Category:Programming languages
Category:Dynamic programming languages
Category:Dynamically typed programming languages
Category:Prototype-based programming languages
Category:Object-oriented programming languages