# HG changeset patch # User IBBoard # Date 1504720502 -3600 # Node ID 4d3769ac447c7c62b17d5177956b8933f1e59304 # Parent 2bbabcbc4802ca01c4eb45569c8e98867a03be24 Add notes and code on methods in Io diff -r 2bbabcbc4802 -r 4d3769ac447c 2-Io/day1-methods.io --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/2-Io/day1-methods.io Wed Sep 06 18:55:02 2017 +0100 @@ -0,0 +1,29 @@ +# Methods are objects, defined by some new notation: +# method(object message[…]) + +# This would show something in REPL but is useless in normal execution +method("This does nothing but print something, but with the line-break" println) +# Methods are of type "Block" +method() type println +# And they can be assigned to slots like values +Car := Object clone +ferrari := Car clone +Car drive := method("Vroom" println) +# Note that "cloning" isn't a one-time thing - we modified Car after creating +# ferrari, but it now has the `drive` method anyway. This is good, but +# doesn't *quite* match the naming +ferrari drive + +# You can also retrieve slots (methods or values), which walks up the heirarchy if necessary +ferrari getSlot("drive") println +# And you can find out what its prototype is +# (i.e. what it inherited from and what exists) +ferrari proto println +# But what if we add something to the ferrari? that isn't covered yet +ferrari name := "My Fast Car" +ferrari proto println +ferrari name println +# It seems to only cover the parent stuff + +# There's also a "master namespace" that all the objects get created in: +Lobby println \ No newline at end of file