RedHat Linux Free Tutorial

Web based School

Red Hat Linux rhl34

Previous Page TOC Next Page



34


Smalltalk/X


This chapter describes Smalltalk/X (ST/X), a fairly complete implementation of the Smalltalk-80 programming environment. Anyone who has used Smalltalk-80 or any other version of Smalltalk will be impressed with this freely available implementation. In this chapter we will see

  • What Smalltalk/X is

  • How to install Smalltalk/X

  • Invoking Smalltalk/X

  • Getting around in Smalltalk/X

This chapter gives you an overview of the Smalltalk/X application. After reading the chapter you should be familiar with the facilities that Smalltalk/X provides and be able to navigate your way through the Smalltalk/X user interface.

What Is Smalltalk/X?


When describing Smalltalk/X, it is probably appropriate to start with a description of Smalltalk itself. Smalltalk is an object-oriented programming language that has been a continuing development project at ParcPlace Systems since the early 1970s. Although it was not the first object-oriented language, it was the first object-oriented language to gain wide use in the industry.

Smalltalk has been around for about 15 years now but it was not until recently that it started to become popular. Many universities now teach a Smalltalk course as part of their standard computer science curriculum, and many companies have seen the value that Smalltalk adds in terms of quick development.

Smalltalk/X was developed by Claus Gittinger and was first released in 1988. It is almost identical to the behavior of the Smalltalk 80 implementation of the Smalltalk language. Smalltalk/X comes complete with an application launcher, several different browsers for browsing through the Smalltalk class hierarchy, and a very powerful debugging utility. The unique aspect of Smalltalk/X is that it can also behave as a Smalltalk-to-C translation utility. This is a very useful feature because this means that you will be able to combine the speed of development that Smalltalk provides with the speed of execution that C provides.

How To Install Smalltalk/X


Before installing Smalltalk/X, you must first retrieve it from sunsite.unc.edu in the /pub/Linux/devel/lang/smalltalkx directory. Once there, you will find the following files:

  • Copy As the filename suggests, this is the SmallTalk/X Copy information document.

  • INDEX Provides a list of files in the directory.

  • LICENSE The distribution license for SmallTalk/X.

  • README Contains a brief discription of how to get SmallTalk/X running.

  • bitmaps.tar.Z Contains sample graphics that can be used to dress up the visual appeal of your programs.

  • doc.tar.Z The documentation set for SmallTalk/X. This package also includes several demos.

  • exe.tar.Z The executable archive. Although this is really the only file you need to download to get SmallTalk/X up and running, installing the bitmap, documentation, goodies, and source files is also highly recommended.

  • goodies.tar.Z Various extras thrown in for your enjoyment.

  • source.tar.Z Support and library files needed to get the most out of SmallTalk/X.

To install Smalltalk/X, perform the following steps as root.

  1. Create a directory called /usr/local/lib/smalltalk.

  2. Copy the following files into the /usr/local/lib/smalltalk directory.
    bitmaps.tar.Z
    doc.tar.Z
    exe.tar.Z
    goodies.tar.Z
    source.tar.Z
  3. Uncompress and untar these files by entering the following commands from the /usr/local/lib/smalltalk directory.
    uncompress *.Z
    tar -xf bitmaps.tar
    tar -xf doc.tar
    tar -xf exe.tar
    tar -xf goodies.tar
    tar -xf source.tar
  4. You can now delete all of the tar files by typing the following command:
    rm -f *.tar
  5. Finally, create the following links:
    ln /usr/i486-linuxaout/lib/libc.so.4 /usr/lib/libc.so.4
    ln /usr/i486-linuxaout/lib/libXt.so.3 /usr/lib/libXt.so.3
    ln /usr/i486-linuxaout/lib/libxll.so.3 /usr/lib/libxll.so.3
    ln /usr/i486-linuxaout/lib/libm.so.4 /usr/lib/libm.so.4

The Smalltalk/X program should now be installed and ready to go.



If you do not have write access to the /usr/local/lib directory, install Smalltalk/X in some other directory by following the same steps listed above. If you do this you must set the SMALLTALK_LIBDIR variable to be equal to the new directory.


Invoking Smalltalk/X


You invoke Smalltalk/X by typing


smalltalk

in an Xterm window from the /usr/local/lib/smalltalk directory. When ST/X starts, it checks to see if there is an image file for it to use. If it cannot find an image file, it uses a file called smalltalk.rc to set up the default behavior for your environment. The image file that is loaded by default is called st.img, and contains a snapshot of what your ST/X environment looked like the last time you exited. This allows you to resume exactly where you left off. You can save a snapshot under any name with the extension .img. To invoke ST/X with an image other than st.img, type the following command at the prompt:


smalltalk -i nameofImage.img

Getting Around in ST/X


Once ST/X is invoked, two windows or views will appear. The Transcript view and the Launcher menu. The Transcript view is shown in Figure 34.1.

Figure 34.1. The Transcript view.

The Transcript is the console where relevant systems information is shown. The Launcher menu is shown in Figure 34.2.

Figure 34.2. The Launcher menu.

The Launcher allows access to the tools you will need to program your application. Table 34.1 gives the options available from the Launcher and a brief description of each.

Table 34.1. The Launcher menu options.

Option Description
Browsers The pull-right menu of this option gives you access to browsers, senders, and implementors.
Workspace This option brings up a workspace view.
FileBrowser This browser allows inspection and manipulation of files and directories.
Projects This option allows you to choose an existing or new project.
Utilities This contains tools specific to your programming needs.
Goodies This contains other non-programming related tools.
Games & Demos This contains some sample programs and games to play.
info & help This contains topics that give you help and information on the ST/X environment and programming in Smalltalk.
snapshot This option takes a snapshot of your present ST/X environment and asks for the name of the image file you wish to store the snapshot in.
exit This option allows you to exit ST/X immediately or exit and save a snapshot of the current environment.

The following sections describe most of these options in more detail.

The Browsers Options


The Browsers option in the Launcher menu gives you access to different browsers or editors that let you read and manipulate classes, methods, changes, senders, and implementors. The sub-options available are

  • System Browser

  • Class Hierarchy Browser

  • Implementors

  • Senders

  • Changes Browser

  • Directory Browser

Each of these sub-options will be discussed in detail in this section.

The System Browser


The standard System Browser contains five subviews:

  • Class category list

  • Class list

  • Method category list

  • Method list

  • Code view

The System Browser is shown in Figure 34.3.

Figure 34.3. The System Browser.

Within the ST/X system, classes are assigned to a category. A category is simply an attribute used for grouping classes to make them easier to handle. To select a class category, click on the name of the category in the class category list. This is the leftmost section of the top half of the System Browser. This will display, in the class list subview, all classes belonging to that category. The class list subview is the second section from the far left of the system browser. You can also select one of two special categories: all *which selects all classes and lists them alphabetically; and *hierarchy, which lists all classes in a tree byinheritance.

If you select a class in the class list, all method categories for that class will be displayed in the method category list, which is the second section from the right in the top half of the System Browser. Like class categories, method categories are simply for grouping methods according to their function. When you select a method category, all methods in that category are shown in the method list view in the far right section of the browser. The special * all * category will show all methods in alphabetical order. Selecting a method from the method list will show the corresponding method's source code in the code view which is the bottom half of the System Browser.

The browser enables you to change either a class or its metaclass. There are two toggle buttons, class and instance, in the same section of the browser as the class list view. Instance, which is the default, makes the changes affect the class. Selecting class makes the changes affect the metaclass.A pop-up menu is available in each view by pressing the middle or menu mouse button while the pointer is in that view. The pop-up menu available in the class category view is shown in Figure 34.4, and the purpose of each function is shown in Table 34.2.

Figure 34.4. The Class Category pop-up menu.

Table 34.2. Class Category pop-up menu functions.

Function Description
fileOut Saves all classes in the currently selected class category into one source file named classCategory.st
fileOut each Saves all classes but puts each class into a separate file called className.st
printOut Sends a printed representation of all classes selected to the printer including the method source code
printOut protocol Sends a protocol-only representation of all classes in the category to the printer without the method's source code
spawn Starts a class category browser without a class category list on the currently selected class category
spawn class Starts a full class browser which allows you to edit all code for the selected class in one view
update Re-scans all classes in the system and updates the lists shown
find class... Pops up a dialog box to enter the name of a class you wish to search for and have displayed
new class category... Displays a dialog for the creation of a new class category.
rename... Renames a category and changes the category attribute of all classes in the currently selected class category
remove Removes all classes and subclasses in the current class category

The class list pop-up menu appears when you press the menu mouse button with the pointer in the class list view. The functions available from this menu are shown in Figure 34.5 and are explained in Table 34.3.

Figure 34.5. The Class List pop-up menu.

Table 34.3. Class List pop-up menu functions.

Function Description
fileOut Saves the source code of the currently selected class in a file named className.st.
printOut Sends the source code of the currently selected class to the printer.
printOut protocol Sends a protocol description of the currently selected class to the printer. The output will contain the class description, class comment, and the classes protocol and method comments.
spawn Starts a class browser on the currently selected class.
spawn hierarchy Starts a browser on all subclasses of the currently selected class.
hierarchy Shows the hierarchy of the currently selected class in the code view.
definition Shows the class definition in the code view and allows you to change the class definition.
comment Shows the class comment in the code view and allows you to edit it.
class instvars Shows the class-instance-variables for the selected class and allows you to edit them.
variable search Provides a search facility to find different variable references and all methods referencing the searched-for variable.
new class Allows you to create a new class using as a template the currently selected class.
new subclass Same as new class but it will create a subclass of the currently selected class.
rename Changes the name of the currently selected class.
remove Removes the currently selected class and all of its subclasses.

The method category pop-up menu appears when you press the menu mouse button while the pointer is in the method category view. The functions available from this menu are shown in Figure 34.6 and explained in Table 34.4.

Figure 34.6. The Method Category pop-up menu.

Table 34.4. Method Category pop-up menu functions.

Function Description
fileOut Saves the source code of the currently selected method category in a file named className-category.st
printOut Sends the source code of the currently selected method category to the printer
spawn Starts a method category browser on the currently selected method category of the currently selected class
spawn category Starts a browser on all methods of the class which have the same category as the currently selected one
find method here... Searches for the method that implements a specified selector
find method... Searches in the class hierarchy for the first class implementing the selector you specify in the dialog box
new category... Enables you to add a new category to the list
copy category... Enables you to copy all methods in a class category to the currently selected class
create access methods Creates methods to access instance variables
rename... Renames the currently selected method category
remove Removes all methods in the currently selected class that are members of the currently selected method category

The method list pop-up menu appears when you press the menu mouse button while the pointer is in the method list view. The functions available from this menu are shown in Figure 34.7 and explained in Table 34.5.

Figure 34.7. The Method List pop-up menu.

Table 34.5. Method List pop-up menu functions.

Function Description
fileOut Saves the currently selected method in a file named className-selector.st
printOut Sends the source code of the currently selected method to the printer
spawn Starts a browser for editing this method
senders... Starts a new browser on all methods sending a specific message
implementors... Starts a new browser on all methods implementing a specific message
globals... Starts a new browser on all methods that are accessing a global that is either a global variable or a symbol, as well as all methods sending a corresponding message
local senders... Same as senders but limits the search to the current class and its subclasses
local implementors... Same as implementors... but limits the search to the current class and its subclasses
new method Enables you to create a new method from a template in the code view
change category... Enables you to change the category of the selected method
remove Removes the currently selected method

When you add or remove instance variables to or from a system class description and accept (that is, save the changes), the system creates a new class instead of changing the old one. The original class still exists to give existing instances of the class a valid class even though it is no longer accessible by name. After the change, you can no longer edit the old class.



It is recommended that you don't change the definition of system classes but only private ones. It is safer to use the copy category function to copy an existing class and its methods to a new class and modify the new class. This is especially important for classes which are used by the system itself since changes can lead to problems in the operation of the ST/X environment.

The code view is the lower half of the System Browser. It is here that you can modify the class or instance definitions as well as methods. The pop-up menu for this area is the edit menu that appears in every text editing view in ST/X. The functions in this menu are discussed in the "Editing in Browsers" section of this chapter.

The Class Hierarchy Browser


When the Class Hierarchy Browser is selected, a dialog box appears which asks for the name of class. If you enter a valid class, the Class Hierarchy Browser appears for that class. This is the same as the System Browser except there is no class category list since this is for one specific class. The pop-up menus for each of the four subviews are the same as in the System Browser.

Implementors


When the Implementors option is selected, a dialog box appears which asks for a selector. A selector is the name of the type of operation a message requests of its receiver.

If you enter a valid selector, an Implementors view will be displayed. This view is similar to the one shown in Figure 34.8.

Figure 34.8. The Implementors view.

The Implementors view contains a list of the methods that implement the method specified by the selector. The pop-up menu for the top half of the Implementor view is the same as the pop-up menu for the method list subview which was discussed in the "System Browser" section of this chapter.

Senders


When the Senders option is selected, a dialog box appears that asks for a selector. If you enter a valid selector, then a Senders view will be displayed. This view is similar to the one shown in Figure 34.9.

Figure 34.9. Senders view.

The Senders view contains a list of the methods that send the selected message. The pop-up menu for the top half of the Senders view is the same as the pop-up menu for the method list subview which was discussed in the "System Browser" section.

The Changes Browser


Each time you make a change to either the class hierarchy or to a method, ST/X writes a record to a changes file. The Changes Browser enables you to inspect and manipulate the changes file. There are two subviews in the Changes Browser; the change list and the contents view. The change list gives a list of all changes in chronological order. A sample Changes Browser is shown in Figure 34.10.

Figure 34.10. The Changes Browser.

To display a change, select one of the changes from the change list. The change browser then displays the contents of the change in the contents view.

The pop-up menu for the change list has the functions described in Table 34.6.

Table 34.6. The Change List pop-up menu.

Function Description
apply change Applies the currently selected change.
apply to end Applies all the changes from the currently selected change to the end of the changes file.
apply all changes Applies all the changes in the file.
delete Deletes the currently selected change from the list.
delete to end Deletes all changes from the currently selected change to the end of the file.
delete changes for Deletes all changes affecting the same class as the currently selected this class change to the end of the changes file.
delete all changes Deletes all changes in the file for the same class as the currently for this class selected change.
update Rereads the changes file.
compress Compresses the change list and removes multiple changes of a method and leaves the most recent change compared to current.
compare with Compares a method's source code in a change with the current current version version of the method and outputs a message in the Transcript view.
make change a patch Appends the change to the end of the patches file which will be run and automatically applied at ST/X startup.
save change a file Saves any changes made to the current file.
update sourcefile This function is not currently implemented.from change
writeback changefile Writes the change list back to the changefile changes file. All delete/compress operations performed in the Change Browser will not affect the changes file unless this operation is performed.

The Change Browser can be used to recover from a system crash by re-applying all changes that were made after the last snapshot entry.



To control the size of the changes file, it is a good idea to apply a compress periodically. This will remove all old changes for a method leaving the newest one.


Directory Browser


When you select the Directory Browser option, a browser with five subviews is displayed. The top half of the browser displays the current directory and all subdirectories and files contained in it. If you select a directory, it is expanded in the next section to the right across the top half of the browser. If you select a file, the contents of the file are displayed in the lower half of the Browser. The pop-up menu for the directory area has only two functions:

  • up—Moves up to the directory above the one selected

  • goto directory—Enables you to go to a specified directory

The content view has the same edit menu as all the other text editors and is discussed in the "Editing in Browsers" section in this chapter. A typical Directory Browser is shown in Figure 34.11.

Figure 34.11. The Directory Browser.

The Workspace Option


The Workspace option displays a view from which you can enter and compile Smalltalk code. The Workspace is usually used as a testing area or scratch pad when coding. You can use it to test your Smalltalk code before building it into the code library using the System Browser code view.

The File Browser Option


The File Browser gives you the ability to inspect and manipulate files and directories. The File Browser is shown in Figure 34.12.

Figure 34.12. The File Browser.

It consists of four subviews that are described in Table 34.7.

Table 34.7. The File Browser subviews.

Subview Purpose
path-label field Shows the name of the current directory
file pattern field Allows a search pattern to be entered for choosing files for the file list
file list Shows a list of file and directory names
contents view Shows the contents of a selected file

To inspect the contents of a file, double-click the left mouse button on the name of the file in the file list. To change directories, double-click on the directory name. Directory names are always shown in the file list.

You can use the file pattern field to display the list of files matching the specified pattern. The default is *, which shows all files. The search pattern can be changed by moving the pointer to the field, editing the pattern, and then pressing enter or choosing accept from the file pattern pop-up menu.

As in the other browsers we have discussed, each subview has a pop-up menu that is activated by the menu mouse button. The path-label pop-up menu is shown in Figure 34.13.

Figure 34.13. The Path-Label pop-up menu.

The functions available in this menu are described in Table 34.8.

Table 34.8. The Path-Label pop-up menu functions.

Function Purpose
copy path Copies the current pathname into the cut and paste buffer
change directory... Opens a dialog box to enter the name of the directory you wish to change to
change to home directory Changes the file list to your home directory

The file list pop-up menu is shown in Figure 34.14.

Figure 34.14. The File List pop-up menu.

The functions available in this menu are described in Table 34.9.

Table 34.9. The File List pop-up menu functions.

Function Purpose
spawn Starts another file browser on the current directory or the directory selected in the file list.
get contents Shows the contents of the currently selected file in the contents view.
show info Displays a view with type, size, access, and owner information for the currently selected file or directory.
show full info Displays the same as above with more details such as the last access, last modification date, and time.
fileIn Loads the selected file into the system by reading and evaluating Smalltalk expressions from it.
update Rereads the directory and updates the file list.
execute unix command_ Allows execution of any UNIX command through a pop-up box.
remove Removes the selected file(s) or directory(s).
rename... Renames the selected file.
display long list Shows file information in the file list. This option toggles with display short list which is the default.
show all files Displays all the files including hidden files. This option toggles with hide hidden files which is the default.
create directory... Creates a new directory.
create file... Creates a new file.

The pop-up menu for the contents view is the same edit menu as the other text editors and is discussed in the "Editing in Browsers" section of this chapter.

The Projects Option


The Projects option of the Launcher menu enables you to create a new project or select a previously created project. When the new project function is selected, a new project is automatically created for you and the new project object appears on your screen. If you select the select project function, a dialog box appears with a list of existing projects from which to choose. Simply select a project and it will be loaded in to the environment.

The Utilities Option


The Utilities option provides thirteen tools that assist you in programming in the ST/X environment. Table 34.10 gives you a brief description of each tool.

Table 34.10. The Utilities option.

Utility Description
Transcript Opens the Transcript view.
Window tree Displays a graphical tree representation of the window hierarchy of all windows that are active or in wait state at the time it was requested.
Class tree Displays a graphical tree representation of the class hierarchy of the system.
Event monitor Displays a view that monitors events.
Process monitor Displays a view that gives information about all currently active or waiting processes. This information changes as the state of the processes change.
Memory monitor Displays a graph that tells you the present memory usage and changes as the memory usage changes.
Memory usage Displays a table of the classes and the number of instances of each, average size, bytes, and percentage of memory used by each.
collect Garbage Runs a Generation Scavenge algorithm to collect short term objects and destroy them. If an object survives long enough, it is moved to an area of memory where it remains until the user requests its collection.
collect Garbage & Same as Collect Garbage but also compresses
compress to recover space.
full screen hardcopy Takes a picture of the screen and asks you for a name of a file with a .tiff extension in which to save the image.
screen area hardcopy Same as Fullscreen hardcopy but for only a specific area of the screen.
view hardcopy Same as Fullscreen hardcopy but for one specific view only.
ScreenSaver Enables you to choose from one of three different screen savers to use in the ST/X environment.

The Goodies Option


The Goodies option of the Launcher menu provides a pull-right menu of six different tools that are useful at any time, not just when you program in Smalltalk. The Goodies are described in Table 34.11.

Table 34.11. The Goodies.

Tool Description
Clock Displays an analog clock in a square with a toggle for the second hand.
Round Clock Same as the clock but it's round and remains visible when it is minimized.
Directory View Displays a pictorial representation of files and directories. A folder represents a directory and a document is a file.
Mail Tool A tool for managing electronic mail.
News Tool A repository for news, information and documents.
Draw Tool A fairly comprehensive tool for drawing diagrams, charts, pictures, and so on.

The Games & Demo Option


Contained in the pull-right menu of this option are games for your enjoyment and example applications that may be useful. The Games & Demos option menu is shown in Figure 34.15.

Figure 34.15. The Games & Demos option menu.

Editing in Browsers


All views that show text allow the usual editing functions of that text through a pop-up menu. The functions available in this menu are described in Table 34.12.

Table 34.12. Editing functions.

Function Description
again Repeats the last edit.
copy Copies the selected text.
cut Cuts the selected text out of the file.
paste Pastes the text that was copied or cut prior to choosing the paste option to the current position of the pointer.
doIt Evaluates the highlighted text.
printIt Prints a representation of the result of the evaluation at the current cursor position.
inspectIt Invokes the Inspector view on the result.
accept Once you have completed editing, you must use this option to save the changes to the file; otherwise, the changes will not be written to the file.
search... Enables you to search for a specific string.
goto... Enables you to move to a specific location in the file.
font... Enables you to change the font of the file.
indent... Enables you to change the indenting of the file.
save as... Enables you to save the file under a different name.
print Prints the file.

To select or highlight text, press the left mouse button over the first character and move the mouse (while pressing the mouse button) to the end of the text you wish to select and then release the mouse button. If you press the left mouse button again, the highlighting is removed and you can select something else.

To scroll through the text, use the scroll bars on the left of the view. By clicking the mouse below or above the thumb, the text scrolls one page for every click. If you press the Shift key at the same time as you click, the text scrolls to the position of the pointer in the scroll bar. This is useful for scrolling rapidly through long documents.

Using the Inspector


The Inspector enables you to inspect an object. It consists of two subviews, one showing the names of the object's instance variables and the other showing the value of the selected instance variable. You can start an inspector by using the inspectIt function on the edit menu or by sending one of the following messages to an object:


anObject inspect

or


anObject basicInspect

The basicInspect command will open a general inspector that shows instance variables as they are physically present in the object. The inspect command is redefined in some classes to open an inspector showing the logical contents of the object.

Using the Debugger


The Debugger is displayed whenever an error occurs in your Smalltalk code. It shows you where the error occurred and how the system got there. The Debugger runs in one of three modes: normal, modal, and inspecting.

When in normal mode and an error occurs in a process, which is not the event handler process, the debugger will start up on top of the erroneous process. This blocks all interaction with the affected process and its views. Other views are still active and respond as usual.

When an error occurs in the Smalltalk event handler process, the debugger starts in modal mode. While a modal debugger is active you cannot interact with any other view.

The inspecting mode can be entered from the ProcessMonitor by the pop-up menu and allows inspection of the state of other processes. But since the debugged process may continue to run, it is only possible to inspect a snapshot of the affected process.

The Debugger contains four subviews:

  • The Context Walkback List shows the context chain that led to the error

  • The Method Source View shows the method that caused the error

  • The Receiver Inspector allows inspection of the receiver of the selected message

  • The Context Inspector provides information about the arguments and local variables of this context.

The Debugger is shown in Figure 34.16.

Figure 34.16. The Debugger.

The functions that are common to each view appear as a set of buttons below the context walkback list. These functions are described in Table 34.13.

Table 34.13. The Debugger function buttons.

Button Description
terminate Terminates the erroneous process
abort Aborts the current activity if possible
return Continues execution as if the selected context returned
restart Continues execution by restarting the selected context
continue Continues execution
step (single step) Lets the process continue execution until the next send is executed in the currently selected context
send (single send) Lets the process continue execution for one message send

The walkback subview has a pop-up menu with the functions described in Table 34.14.

Table 34.14. Walkback Subview pop-up menu function.

Function Description
exit smalltalk Leaves ST/X without saving an image
show more Shows 50 more contexts of the walk-back
breakpoints Not yet available
trace on/off Not yet available
trace step Not yet available

A miniDebugger is entered if an error occurs within the Debugger itself. This is a line-by-line debugger that allows limited debugging without the use of a graphical user interface. It is controlled by entering commands in the Xterm window where ST/X was started. If you type ? at the miniDebugger prompt, you will get a list of commands that are available for use in this stripped down debugger.

Summary


This chapter introduced you to the Smalltalk environment that is provided by the Smalltalk/X application. If you are interested in learning how to program using Smalltalk and do not have access to one of the commercial versions of Smalltalk, then Smalltalk/X is perfect for you. Not only does Smalltalk/X come with all the tools and programming aids that were talked about in this chapter, but it also comes with many examples and some fairly complete documentation that will make learning Smalltalk easier for you.

Previous Page Page Top TOC Next Page