Mercurial > repos > other > SevenLanguagesInSevenWeeks
view 2-Io/day1-methods.io @ 77:7bab4843aec6
Add roulette with auto-restarting process
(And black-magic auto-registering of atoms)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 03 Feb 2018 20:42:51 +0000 |
parents | 4d3769ac447c |
children |
line wrap: on
line source
# 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