Skip to content

Instantly share code, notes, and snippets.

@japaz
Created October 4, 2011 21:09
Show Gist options
  • Save japaz/1262820 to your computer and use it in GitHub Desktop.
Save japaz/1262820 to your computer and use it in GitHub Desktop.
7L7W Io - Day 1
// Evaluate 1 + 1 and then 1 + "one". Is Io strongly typed or weakly typed? Support your answer with code.
// It seems strongly typed to me
1+1
// ==> 2
1+"one"
// Exception: argument 0 to method '+' must be a Number, not a 'Sequence'
// ---------
// message '+' in 'Command Line' on line 1
// But you can do think like this
Vehicle := Object clone
// ==> Vehicle_0xc4d760:
// type = "Vehicle"
Car := Vehicle clone
//==> Car_0xc9fd68:
// type = "Car"
Person := Object clone
//==> Person_0xbf4dc0:
// type = "Person"
Car = Person
//==> Person_0xbf4dc0:
// type = "Person"
Car type
//==> Person
// This make me doubt about if it is strongly typed
// Is 0 true or false?
// true
// Support your answer with code.
0 and true
//==> true
0 or true
//==> true
0 and false
//==> false
0 or false
//==> true
// What about the empty string?
// true
// Support your answer with code.
"" and true
//==> true
"" or true
//==> true
"" and false
//==> false
"" or false
//==> true
// Is nil true or false?
// false
// Support your answer with code.
nil and true
//==> false
nil or true
//==> true
nil and false
//==> false
nil or false
//==> false
// How can you tell what slots a prototype supports?
// with the method proto
Car proto
// What is the difference between = (equals), := (colon equals), and ::=
// (colon colon equals)? When would you use each one?
// = is a comparator, and also is sed to assign a value to an slot, but don't create if the slot doesn't exists
// := used to assign a value to an slot, but it creates the slot if it doesn't exists
// ::= used to assign a value to an slot, it creates the slot if it doesn't exists and also a setter
Luis := Person clone
//==> Luis_0xc99678:
// type = "Luis"
Luis slotNames
//==> list("type")
Luis a := 1
//==> 1
Luis b := 2
//==> 2
Luis slotNames
//==> list("type", "b", "a")
Luis c ::= 3
//==> 3
Luis slotNames
//==> list("c", "type", "a", "setC", "b")
// Run an Io program from a file.
// Simple run io <filename>.io (io extension is convention)
// Execute the code in a slot given its name.
// I really don't know what are he asking. If it is just sending the message with the name of the slot to the object, it seems too obviously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment