Io

Prototype based programming

Steve Dekorte, 2002


Account := Object clone
Account balance := 0

Account deposit := method(amount,
  balance = balance + amount
)

account := Account clone
account deposit(100)
account balance println

Animal := Object clone

Animal type
==> Animal

Animal slotNames
==> list(type)

Animal description := "Something"

Animal slotNames
==> list(type, description)

Dog := Animal clone

Dog type
==> Dog

Dog description
==> something

Dog slotNames
==> list(type)

Dog description := "Man's best friend"
Dog slotNames
==> list(type, description)

dog = Dog clone
dog type
==> Dog

dog slotNames
==> list()

dog name := "Pluto"

dog slotNames
==> list(name)
    Io> Lobby
    ==>  Object_0x7fe5eac1c220:
    Animal           = Animal_0x7fe5eafc51d0
    Dog              = Dog_0x7fe5ec095020
    Lobby            = Object_0x7fe5eac1c220
    Protos           = Object_0x7fe5eac1b510
    _                = Object_0x7fe5eac1c220
    dog              = Dog_0x7fe5eae91740
    exit             = method(...)
    forward          = method(...)
    set_             = method(...)

Lists


a := list(2, 1, 4, 3)
a sort
a sum
a average
a pop

Lists


a := list(2, 1, 4, 3)

a select(i, i%2 == 0)
==> list(2, 4)

a map(* 10)
==> list(20, 10, 40, 30)

Looping


x := 0
while(x < 5,
  x println
  x = x + 1
)

Looping


for(i, 1, 5,
  i println
)

Conditions


if(answer == 42,
  "Correct answer!" println,
  "Wrong answer!" println
)

my_if := method(cond, then_do, else_do,
  if(cond, then_do, else_do)
)

my_if(answer == 42,
  "Launch missiles" println,
  "Abort" println
)

my_if := method(
  if(call evalArgAt(0),
    call evalArgAt(1),
    call evalArgAt(2)
  )
)

iolanguage.org


@nithinbekal

nithinbekal.com