1. Read the first seven pages of chapter 10, which starts on page 777. For each of the parts, pick exactly one of the numbered responses in that part. (a) What is a "receiver"? What is an "argument"? 1. A receiver is the method that the message dispatches to, and an argument is a value that is bound to a formal parameter in a method body. 2. A receiver is the object that a message is sent to, and an argument is a value that is bound to a formal parameter in a method body. 3. A receiver is a message that is sent to some object, and an argument is also a message that is sent to some object. (b) What is the relationship between a _message_ and a _protocol_? 1. A protocol says what messages can be sent 2. A protocol is an object, and a message is a value sent to that object 3. A protocol is the same as a class, and a message is something that can be sent to instances of that class (c) What is the difference between _instance_ protocol and _class_ protocol? 1. Messages defined for a class protocol can be sent to both instances of the class and the class itself, but messages defined for an instance protocol can be sent to only to the instances 2. Messages defined for a class protocol can only be sent to the class itself, but messages defined for an instance protocol can be sent to both instances of the class and the class itself 3. Messages defined for a class protocol can be sent to the class itself, and messages defined for an instance protocol can be sent to only to the instances (d) In the name of a message, what is the significance of a colon or colons? 1. The colons make the message code go faster; i.e. if a message has a large number of colons the message runs faster 2. The colons indicate the number of arguments expected; i.e. if a message has `n` number of colons it expects `n` actual parameters 3. The colon indicates that the message is only part of a class protocol; i.e. if a message has more than 0 colons it should only be sent to a class and not to an instance of the class 2. Read Section 10.3.4 on message send and dynamic dispatch. Using the class definitions in that section, message `m1` is sent to an object of class `C`: What method *definitions* are dispatched to in what order? An answer looks something like "method m5 on class H, then method m12 on class E, ...". 3. Continuing with method dispatch, now study the *class* method `new` defined on class `List` just after page 847. The definition sends message `new` to `super`. (Keep in mind: because `new` is a *class* method, both `super` and `self` stand for the class, not for any instance.) (a) When *class* method `new` is executed, what three messages are sent by the method body, in what order? (b) What does each message send accomplish? (c) If we changed the body so instead of `(new super)` it said `(new self)`, what would happen? Pick one of the numbers below to answer this part. 1) The `new` message would indefinitely be dispatched to `self`'s class, because that's what we're implementing. The program would then fail to terminate. 2) The sentinel would point to the wrong value 3) The sentinel gets initialized correctly; so, there's no difference between `(new super)` and `(new self)` here. 4. Find the implementation of class `Number` starting around page 853. Now study the implementation of class `Fraction` starting around page 857. Message `-` (minus) is sent to `Fraction` `(/ 1 2)` with argument `Fraction` `(/ 1 3)`. What methods are executed in what order? Which class implements `-`? You are getting ready for exercise 39(a). 5. Read about the `Magnitude` protocol on pages 814 and 815. Study the implementation of class `Magnitude` on page 853. Then study the implementations of classes `Integer` and `SmallInteger` starting on page 855. Message `<=` is sent to small integer 3 with argument 9. What methods are executed in what order? Which class implements `<=`? You are ready for exercise 39(a), and you are ready to implement class `Natural` (exercise 42). 6. In section 10.10.1 on page 900, you will find a short definition of an "abstract class." What do you think is the purpose of an abstract class? Pick one of the lettered responses below. (a) An abstract class' purpose is to hide the implementation of instances from clients so that the creator of the class can change internal details without affecting clients (b) An abstract class' purpose is to define methods that other classes inherit. It's a way to provide default implementations that subclasses could use. (c) An abstract class' purpose is no different from a (non-abstract) class' purpose. 7. One example of an abstract class is class `Number`. Look up its definition starting around page 853. We've copied many of the methods defined on `Number` below. To answer this question, please write down the corresponding letter for each of method that you must implement on the `LargeInteger` class. Some methods you will have to implement may not be listed below. (a) `+` (b) `*` (c) `negated` (d) `asFraction` (e) `asFloat` (f) `coerce` (g) `negative` (h) `nonnegative` (i) `strictlyPositive` (j) `=` (k) `<` (l) `>` (m) `<=` You are getting ready to implement large integers. 8. Read Section 10.6.5, which starts on page 852. Of the methods listed in comprehension question 7 (subclass responsibilities of `Number`), list each one that needs to know whether its *argument* (not the receiver) is a large or small integer, and if large, whether it is positive or negative. These methods will require double dispatch. (a) List the methods by their corresponding letter. For example, `+` is such a method, so you would at least write (a) (b) For each method, list what method it will dispatch to on its argument if the received is a `LargePositiveInteger`. For example, method `+` will dispatch to `addLargePositiveIntegerTo:` so at least write (a) will dispatch to `addLargePositiveIntegerTo:` You are ready to implement large integers (Exercise 43). 9. Read about coercion in section Section 10.4.6 on page 815. Look at the protocol on page 814. Explain the roles of the methods `asInteger`, `asFraction`, `asFloat`, and `coerce:`. If you are unsure, look at the implementations of these methods on class `Integer` starting on page 855. You are ready to implement mixed arithmetic, with coercions, in Exercise 44.