# HG changeset patch # User IBBoard # Date 1504724075 -3600 # Node ID 22edfbf3b8bde14e4f360b72ae51ecbfc9c01f1e # Parent 3d41d9d72cc916463e1fcb85e30d82491f3d2775 Add most of the self-study answers diff -r 3d41d9d72cc9 -r 22edfbf3b8bd 2-Io/day1-self-study.io --- /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