annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 # Calling "functions" is sending a "message" (right) to an object (left)
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 # ↓ object ↓ message
31
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
3 "Hi ho, Io" println
28
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 # Object creation is by cloning and modifying root "Object" object
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 # Convention appears to be that classes start with capitals
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 Vehicle := Object clone
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 # ":=" creates a "slot" (which can be a value or a function?), whereas "=" assigns to existing ones
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 Vehicle description := "A description of our vehicle"
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 # 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!
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 # Vehicle another_field = "This won't work"
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13
29
9c7af76fdbd0 Print isn't PrinLn, so add some \n characters to the output
IBBoard <dev@ibboard.co.uk>
parents: 28
diff changeset
14 # Fetching values is just calling the function
9c7af76fdbd0 Print isn't PrinLn, so add some \n characters to the output
IBBoard <dev@ibboard.co.uk>
parents: 28
diff changeset
15 # (but we need to skip ahead of what's in the book and chain an extra "print" to print to stdout)
31
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
16 Vehicle description println
28
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 # In addition to the slot we created, there is a default slot called "type"
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 # (and presumably some default messages, because slotNames apparently isn't a slot!)
31
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
20 Vehicle slotNames println
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
21 Vehicle type println
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
22 Object type println
28
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
30
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
24 # Now we start making a Ferrari as a type of car
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
25 Car := Vehicle clone
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
26 # Car only directly has one slot
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
27 # (Q: How do we find out inhereted slots?)
31
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
28 Car slotNames println
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
29 Car type println
30
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
30 # But because of prototype cloning, the description remains the same
31
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
31 Car description println
30
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
32
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
33 # Now we make a specifc car
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
34 ferrari := Car clone
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
35 # But this hasn't gained any slots because it is lower-case
31
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
36 ferrari slotNames println
30
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
37 # It does still have a type, though
31
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
38 ferrari type println
30
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
39
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
40 # Types don't mean anything specific - they're just a handy convention
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
41 # Variables are case sensitive, so we can make an entire type of Ferraris
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
42 Ferrari := Car clone
31
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
43 Ferrari type println
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
44 Ferrari slotNames println
30
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
45 # And the lower-case version is unaffected
31
2bbabcbc4802 Swap to println after finding out about it in the next section
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
46 ferrari slotNames println
30
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
47
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
48
d43f60e98f39 Complete the car example of objects and types
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
49
28
25e66d77e1fe Start the Day 1 excercises for Io and document the interactive stuff
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 Vehicle another_field = "This won't work"