2 How do numbers fit into an OO framework.
4 Number for which you can do
10 There are several options:
12 A/ Number objects can be immutable
13 B/ Number objects can be mutable and assignment makes a copy
14 C/ Number objects can be mutable and assignment takes a reference.
16 If numbers are immutable, then what does
19 means? It must mean that a new object is created which has a value
20 one more than that value of the object stored in i, and this object is
21 then stored in i. So '++' operates on the name, not on the object.
22 That seems a bit out of the spirit of oo where we operate on objects.
25 If assignment makes a copy, then that is a problem for complex
26 objects. We absolutely need by-reference handling for many things.
27 So we would some-how needs different assignment for different
28 objects. So take references, some take copies. The difference would
29 have to be explicit e.g.
36 If mutable objects assign by reference then
40 would never stop, so the model is unexpected and error prone.
42 So... where does that leave us?
44 It seems that operators:
46 should really create new objects.
49 Really must change the left-hand object
51 So assignments of number really really wants to be a value-copy.
52 Maybe we use type tags to make it harder to go wrong.
55 Always makes 'a' a new object distinct from b.
57 Always makes 'a' refer to the same object as b
59 is the same as =&, but is not allowed for 'bycopy' objects.
61 Hmm.. what sort of assignment happens to formal variables in a
62 function call. They should be by reference, but maybe changing the
63 reference of a formal parameter shouldn't be permitted as that could
68 Instead of two difference sorts of assignment, we could have
69 auto-dereference objects.
70 If a type is strict-once, the there is guaranteed never to be any
73 the '+' creates a new object with sum of b and c and it is assigned by
74 reference to a. As there is no risk of an alias, no 'copy' is needed.
77 The object has a reference already, so to avoid counting the reference
79 So what happens in a function call where we want a by-reference
81 We must be able to over-ride the auto-copy, but we still don't want
82 reference counting. So we need to know that one reference will
83 outlive the other. In that case we use '&' to make a reference.
84 For a function call, it is clear that the actual parameter reference
88 we can probably use data-flow analysis to know when the object is