view 2-Io/day1-collections.io @ 77:7bab4843aec6

Add roulette with auto-restarting process (And black-magic auto-registering of atoms)
author IBBoard <dev@ibboard.co.uk>
date Sat, 03 Feb 2018 20:42:51 +0000
parents 4e1a659f8383
children
line wrap: on
line source

# Io has Lists and Maps as collections
toDos := list("Task 1", "Task 2")
toDos size println
# Calling a method with arguments is like most other languages
toDos append("Task 3")
toDos size println

# Lists are like arrays and are zero-indexed
list(1, 2, 3) at(1) println
# Lists can act like stacks and queues
list(1, 2, 3) prepend(0) println
list(1, 2, 3) append(4) println
list(1, 2, 3) push(4) println
list(1, 2, 3) pop println
list() isEmpty println
# Lists can also do some basic maths
list(1, 2, 3, 4) average println
list(1, 2, 3, 4) sum println

# Map is a prototype to be cloned
rincewind := Map clone
rincewind atPut("home", "Unseen University, Ankh Morpork")
rincewind at("home") println
rincewind atPut("job", "Wizzard")
rincewind at("job") println

# Maps can be turned in to objects with slots and lists (of (two-element) lists)
rincewind asObject println
rincewind asObject home println
rincewind asList println

# You can also pull keys from a map
rincewind keys println