Mercurial > repos > other > SevenLanguagesInSevenWeeks
diff 2-Io/day1.io @ 30:d43f60e98f39
Complete the car example of objects and types
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 06 Sep 2017 18:42:44 +0100 |
parents | 9c7af76fdbd0 |
children | 2bbabcbc4802 |
line wrap: on
line diff
--- a/2-Io/day1.io Wed Sep 06 18:36:02 2017 +0100 +++ b/2-Io/day1.io Wed Sep 06 18:42:44 2017 +0100 @@ -25,4 +25,38 @@ Object type print "\n" print +# Now we start making a Ferrari as a type of car +Car := Vehicle clone +# Car only directly has one slot +# (Q: How do we find out inhereted slots?) +Car slotNames print +"\n" print +Car type print +"\n" print +# But because of prototype cloning, the description remains the same +Car description print +"\n" print + +# Now we make a specifc car +ferrari := Car clone +# But this hasn't gained any slots because it is lower-case +ferrari slotNames print +"\n" print +# It does still have a type, though +ferrari type print +"\n" print + +# Types don't mean anything specific - they're just a handy convention +# Variables are case sensitive, so we can make an entire type of Ferraris +Ferrari := Car clone +Ferrari type print +"\n" print +Ferrari slotNames print +"\n" print +# And the lower-case version is unaffected +ferrari slotNames print +"\n" print + + + Vehicle another_field = "This won't work" \ No newline at end of file