changeset 33:4e1a659f8383

Work through how Io does lists and maps
author IBBoard <dev@ibboard.co.uk>
date Wed, 06 Sep 2017 19:06:46 +0100
parents 4d3769ac447c
children 3d41d9d72cc9
files 2-Io/day1-collections.io
diffstat 1 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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