changeset 35:22edfbf3b8bd

Add most of the self-study answers
author IBBoard <dev@ibboard.co.uk>
date Wed, 06 Sep 2017 19:54:35 +0100
parents 3d41d9d72cc9
children 15eb99e79dd4
files 2-Io/day1-self-study.io
diffstat 1 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/2-Io/day1-self-study.io	Wed Sep 06 19:54:35 2017 +0100
@@ -0,0 +1,46 @@
+#Truthiness:
+# We already know that 0 is truthy
+(true and 0) println
+# Empty strings are apparently truthy
+(true and "") println
+# As are empty lists
+(true and list()) println
+# But nil is falsey
+(true and nil) println
+# So basically anything except `false` and `nil` is truthy
+
+# = vs := vs ::=
+# Obvious part so far is that you must create with := before being able to assign with plain =
+myvar := Object clone
+myvar println
+myvar = Object clone
+# Docs say:
+#    ::= 	Creates slot, creates setter, assigns value
+#    := 	Creates slot, assigns value
+#    = 	Assigns value to slot if it exists, otherwise raises exception 
+# But what is a "setter" in this context?
+myvar foo ::= Object clone
+myvar println
+# It seems we get a "setX" method, which helps us do some things in certain contexts:
+# https://stackoverflow.com/a/5977757
+
+# What slots does a prototype support? Direct ones are human readable in the output
+myvar proto println
+# But they're not listed indirectly
+SubClass := Object clone
+myvar2 := SubClass clone
+myvar2 proto println
+# Can we find it out programattically?
+# It's not recursive, but the type should tell us:
+myvar2 type proto println
+# Except the value of `type` is just a string (or Sequence in Io), so it doesn't
+myvar2 type proto type println
+# Or, of course, a Prototype is a named object that starts with a capital letter
+# So we can just use slotNames to get them programmatically (but that only shows direct slots)
+SubClass slotNames println
+
+# Is Io strongly or weakly typed?
+(1 + 1) println
+(1 + "one") println
+# Exception: argument 0 to method '+' must be a Number, not a 'Sequence'
+# Therefore strongly typed
\ No newline at end of file