Language Roulette 2015-08-05
Ian Preston
What is Io?
Hello world
"Hello, world" println
Syntax & Semantics
Message Passing
// Message passing takes this format:
// objectName messageName(arg0, arg1)
"Hello, world!" println
myObject myMessage(10, "foo")
Operators
// Assignment Operators:
x := 10
y := "Hello, world!"
x = 11
// The usual comparison operators:
5 > 10
true == false
a != a
// The usual control operators:
break
continue
return 10
method()
// Define methods with method()
// method() itself is a method...
x := method("Hello, world!" println)
// Methods can take arguments:
y := method(a, b, a + b)
// Separate statements with semicolons
z := method(someObject doSomething; someObject doSomethingElse)
if(), for(), while()
// if(), while(), and for() are all methods
if(true, "Yes!" println, "No" println)
for(x, 0, 10, x println)
while(true, "infinite loop" println)
Objects: Cloning
// Create Dog by cloning Object
Dog := Object clone
// Set the slot "bark" on Dog to a new method
Dog bark := method("Woof" println)
// Create an "instance" by cloning Dog
fido := Dog clone
fido bark
// Override bark for this instance
fido bark := method("Ruff println")
fido bark
Objects: Slots
foo := Object clone
// Slots can contain any value
foo x := false
foo y := method(return "Return value of y")
foo z := list(1, 2, 3)
// Assignment operators are sugar for updateSlot and setSlot
foo updateSlot("name", "Io")
// Methods are automatically called when referenced
foo y == "Return value of y"
// Introspection:
foo protos
foo slotNames
foo getSlot("name")
Lists
x := List clone
x append("foo")
x append(5)
x foreach(i, v, v println)
x map(v, v + 1)
Sequences (strings)
x := "Hello, world!"
x split(" ")
x asLowercase containsSeq("hello")
"42" asNumber
Everything is an Object
// "Builtin" methods like method() or for() are just slots of Object
// These two are equivalent:
x := method()
x := Object method()
// The global scope is an object called Lobby
// These two are equivalent:
x := 10
Lobby x := 10
// Methods are objects
// This is valid:
x := method()
x someSlot := 10
Scoping
Modules
Links