Try The Following Samples of Smalltalk

A Few Things to Try

Enter the following into a workspace. Then apply showIt to each in turn.

'hello' at: 1 put: $1

Transcript cr;
    nextPutAll:'Hello';
cr.
'Next Try PrintOn' PrintOn:Transcript.

|myString|
myString :='Hello'.
myString at:1 put: $1.
Transcript cr.
myString printOn: Transcript.
Transcript cr.

Getting The Right Message and Debugging

We will trace the call to the following message to see how Smalltalk determines what message to call. Before evaluating the message below get the class browser, by selecting Browse Classes from the file menu.

Find the + message for the class Fraction. Insert the line self halt. as shown below. Save the message, then execute the following (1/3) + 2.3 in your workspace.

The following error dialog comes up when you hit the halt. These are the colors that the people who wrote the compiler chose. I didn't pick the colors-for once.

You can now trace the program by selecting the Debug button in the error window and finding the message you want to trace in the Debug window. You will notice that the program stopped at the halt instruction which is highlighted.

The hop, skip and jump functions can be used to trace the sequence of message calls. Use hop to move through the program. Notice that the messages numerator and denominator called here are the messages for the class Number not the class Fraction. This is because 2.3 is a Float. The class Float does not have either of these functions, so the message must be inherited from the parent class Number. Also note that the * message used is eventually the Float * message. From this point on operations must be float, so denominator is converted to a Float by the asFloat message. If you were to build a class of Complex Numbers you would have to model the mixed operation handling on that which you see in this example.