Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
These concepts of messages, receivers, objects etc. will be explained in a later chapter. Hopefully,<br />
by the end of this book you will read the above definition <strong><strong>an</strong>d</strong> say “of course”.<br />
5.7 Working with <strong>Smalltalk</strong><br />
5.7.1 Open a VisualWorks image<br />
First of all start up your current VisualWorks image, for example, on a UNIX system you might enter:<br />
visualworks Visual.im<br />
If this is not local you may need to specify a path name for the object engine or the image. For example,<br />
if you are on a UNIX system:<br />
/usr/local/ visual/bin/visualworks<br />
/usr/jjh/visual.im<br />
If you are using a Macintosh or a Windows -95 PC then you just double click on the image file <strong><strong>an</strong>d</strong> the<br />
VisualWorks virtual machine will be used to open it.<br />
Once you have started VisualWorks, save the image to your own file store <strong><strong>an</strong>d</strong> exit. To do this, first<br />
select the save as option off the file menu on the VisualLauncher. You will be requested to provide a<br />
name for your image. Note that if you do not give a path name as well as the image name, the image file<br />
will be saved in the current directory.<br />
Once you have created the image file, you c<strong>an</strong> exit from VisualWorks. To do this you select the Exit<br />
option (again from the File menu on the VisualLauncher).<br />
5.7.2 Selecting, compiling <strong><strong>an</strong>d</strong> executing <strong>Smalltalk</strong><br />
If you have not already done so, type the following into the Workspace:<br />
Tr<strong>an</strong>script show: 'Hello World'.<br />
Tr<strong>an</strong>script cr.<br />
Tr<strong>an</strong>script show: (3 + 4) printString.<br />
Tr<strong>an</strong>script cr.<br />
Select the text <strong><strong>an</strong>d</strong> do it. That is, select the text with the left mouse button, then bring u p the right<br />
(or middle on a three button mouse) mouse menu <strong><strong>an</strong>d</strong> select the do it option. You should then see the<br />
phrase “Hello World” <strong><strong>an</strong>d</strong> the number 7 appear in the Tr<strong>an</strong>script window.<br />
5.7.3 Using some VisualWorks tools<br />
In m<strong>an</strong>y books you are presented with some so urce code to type in <strong><strong>an</strong>d</strong> execute, but are given very little<br />
guid<strong>an</strong>ce on how to deal with errors etc. Therefore in this section, you get to type in some (intentionally<br />
buggy) <strong>Smalltalk</strong> code <strong><strong>an</strong>d</strong> to compile it. This forces you to use tools such as the debugge r to identify<br />
<strong><strong>an</strong>d</strong> correct the errors. After all, at this stage, it is likely that you will write buggy <strong>Smalltalk</strong> rather th<strong>an</strong><br />
perfect <strong>Smalltalk</strong>.<br />
Type in the following exactly as it is (there are errors included so that you get some practice using<br />
the tools available in <strong>Smalltalk</strong>).<br />
| temp |<br />
temp := Set New.<br />
temp add: 'John'.<br />
temp add: 'Paul'.<br />
temp add: Peter.<br />
temp do: [:item | Tr<strong>an</strong>script show item].<br />
temp inspect.<br />
Now select all the code <strong><strong>an</strong>d</strong> “do it” as before. You should now get a dialog box such as that<br />
illustrated below:<br />
57