Introducing the Debugger
Did you notice anything wrong with the calculator's behavior? When you press the Pi button, a new window opens. This is a Debugger window, which opens automatically in Smalltalk when an error is encountered.
calculator debubger
The top left pane contains a list of current error messages. Right now there is only one: the phrase item is not valid.
The pane below that is the message stack, sometimes called a walkback. Each line shows a class name followed by the method name. This stack traces the execution of code (message sending) through different classes.
Using the Debugger
Let's look for the error (if you have not yet done so, press the Pi button on the calculator to bring up the Debugger):
1. Scroll down the message stack and look for the class STCalculator.
2. Select the line that reads STCalculator>>#insert:.
3. Note that the text pane displays the source code for the insert: method. The part of code that was executing when an error was encountered is highlighted.
4. The pane second from the right shows the current variables. In this case, there is self, which the right pane describes as being an STCalculator.
5. Select aString in the variables pane. You can see in the right pane that its value is pi. But wait, something is wrong. The argument aString is supposed to be a string. It looks like it is a float instead.
6. Select the next method down, STCalculator>>#pi. Now you can see the problem. This method obtains the value of pi from the Float class, which returns a float. The method insert:, however, expects a string as the argument.
7. You can fix the code here in the Debugger. Edit the text pane to make the method read:
pi
"The pi button has been pressed. Display its value."
self insert: (Float pi printString)
8. Save the method from the Debugger, using the pop-up menu of the text pane.
9. Now go back to the Calculator window and press Pi. Notice that you can use the same window, and the change is reflected in the calculator instantly.
10. Close the Debugger.
Last modified date: 03/26/2020