Mercurial > repos > other > SevenLanguagesInSevenWeeks
changeset 32:4d3769ac447c
Add notes and code on methods in Io
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 06 Sep 2017 18:55:02 +0100 |
parents | 2bbabcbc4802 |
children | 4e1a659f8383 |
files | 2-Io/day1-methods.io |
diffstat | 1 files changed, 29 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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