# HG changeset patch # User IBBoard # Date 1504721206 -3600 # Node ID 4e1a659f83830935e2830235b282a3b419f3eb6e # Parent 4d3769ac447c7c62b17d5177956b8933f1e59304 Work through how Io does lists and maps diff -r 4d3769ac447c -r 4e1a659f8383 2-Io/day1-collections.io --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/2-Io/day1-collections.io Wed Sep 06 19:06:46 2017 +0100 @@ -0,0 +1,33 @@ +# 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