========================================= Notes for: Date today. 29 April 1996 ========================================= Administrative: Laptop update: sightings in NYC, Dallas Readings: TBA Problem set S1: out Wednesday, due Friday 5/10 ========================================= 1. Message passing precedence First process all the unary messages left to right. Then process all the binary messages left to right. Then process all the n-ary messages left to right. In the last case there is a potential ambiguity, for example: 3 + 2 add: 7 / 9 negated divide: 1.25. The first two steps are unambiguous: 3 + 2 add: 7 / -9 divide: 1.25. 5 add: -.03 divide: 1.25 multiply: 6.2 But now is the message dispatch to -- the shortest message, 5 add: -.03 or -- the longest message 5 add:divide:multiply: or -- to the message (if any) that 5 can actually respond to? The third is impossible: the Smalltalk equivalent of the REPL will not look to see what the receiver is capable of handling. The smalltalk convention is to parse the *longest* message possible, so presumably incorrectly, the integer 5 will be sent add:divide:multiply. You can always use parens to influence execution order: 5 add: ((-.03 divide: (1.25 multiply: 6.2))) ================================================ 2. The Temperature class We continued defining this class. Things to recall: -- we ended up defining a class variable InternalScale that stored how the temperatures were stored internally -- that meant we needed a class method initialize to set that variable -- in instance creation, we tried but could not set the instance variables. That's because farenheit: and celsius: are class methods, thus don't have access to the instance variables except by sending a message to the instance itself. There are two ways to get around this problem: * define "setters" for the instance variables at the instance level, and the instance creation method can call them. This is perhaps not good because it means that setters are globally defined, even if they are not otherwise used. * define an "initialize" method at the instance level, and pass in all the initial values. We implemented both of these techniques. -- we built a method for converting between two different units. This was defined at the class level because the computation doesn't depend on any data in the instance itself. -- the standard way to signal an error: self error: 'This is an error message'. The Smalltalk convention is not to send a lot of information in the error message: you will get a debugger window, and can look at the code and local variables there. For next time: -- finish the initialization code at the instance level -- write accessors for the instance -- define a print method for the instance -- define an addition method.