Mercurial > repos > other > SevenLanguagesInSevenWeeks
view 2-Io/day1.io @ 60:643eec1f9e3a
Add a custom implementation of append/3
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 27 Sep 2017 20:48:28 +0100 |
parents | 2bbabcbc4802 |
children |
line wrap: on
line source
# Calling "functions" is sending a "message" (right) to an object (left) # ↓ object ↓ message "Hi ho, Io" println # Object creation is by cloning and modifying root "Object" object # Convention appears to be that classes start with capitals Vehicle := Object clone # ":=" creates a "slot" (which can be a value or a function?), whereas "=" assigns to existing ones Vehicle description := "A description of our vehicle" # So this would fail because the slot doesn't exist - we'll repeat it at the end to stop it crashing our program too early! # Vehicle another_field = "This won't work" # Fetching values is just calling the function # (but we need to skip ahead of what's in the book and chain an extra "print" to print to stdout) Vehicle description println # In addition to the slot we created, there is a default slot called "type" # (and presumably some default messages, because slotNames apparently isn't a slot!) Vehicle slotNames println Vehicle type println Object type println # 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 println Car type println # But because of prototype cloning, the description remains the same Car description println # Now we make a specifc car ferrari := Car clone # But this hasn't gained any slots because it is lower-case ferrari slotNames println # It does still have a type, though ferrari type println # 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 println Ferrari slotNames println # And the lower-case version is unaffected ferrari slotNames println Vehicle another_field = "This won't work"