Help with Squeak (a Smalltalk implementation)

Most of the following is text. This is a deliberate choice, as it is easy to edit, provides a lowest common denominator for all browsers, and makes the page easily indexable by search engines. For more visual presentations, see:

Getting and running Squeak

The Squeak homepage is (mirrored at Download it from there, and unpack the archive. There will be a Squeak executable, which you can run directly.

This is all you need to know if you just want to play around. Further instructions for using Squeak in the labs are below.

After you've gotten Squeak running, you will probably want to do save your system as a fresh image file and then begin working in your own project. Read the notes below on using Squeak and saving your work for more details.

What version of Squeak should I use?

The version used in the Mark Guzdial text is 2.7; the CD included with the book has both 2.7 and 2.8 on it. The current released version is 3.8. If you want to use the examples in the book with minimal confusion, use 2.7. If you want to have the latest bells and whistles, and don't mind adjusting yourself mentally to the new environment (which uses the Morphic library much more heavily), then use Squeak 3.8.

However, probably all of the examples used in lecture will work on any of these versions. The Squeak language (as opposed to the Squeak environment) is basically vanilla Smalltalk, and is the same across all Squeak versions.

Squeak on Windows machines in the undergrad lab

Squeak is stored in c:\Program Files\squeak. Double-click on the mouse to start. You can make any changes you want to Squeak, but when you log out, all of your files on C: will be wiped clean -- so if you make any changes you care about, file out the changes and put the fileout file on a server.

Alternatively, you can get your own copy of Squeak and work out of your network home directory. Then you can save your workspace when you quit, and resume right where you left off. Here's how:

  1. Download the Squeak archive.
  2. Map your home directory (either your NT home directory on \\IFILESRV1\Students\username or your Unix home directory on \\Ntdfs\cs\unix\homes\iws\username) as a network drive (e.g., Z:). You must do this because Squeak does not like Windows network shares to appear directly in path names. If you don't know how to map a network drive, see these directions
  3. Create a subdirectory off your home directory in which to store your Squeak files.
  4. Unzip the Squeak archive into this subdirectory.
  5. Double-click the Squeak icon. It will typically take a little while for Squeak to read its image over the network, so do not be alarmed if the window does not appear right away.

Using Squeak on your home Windows/Mac

Instructions are pretty much as above (for working out of your network home directory), except you don't have to map any network drives or such. Just download Squeak, extract the archive to its own folder, and run it. You will want to see the notes about saving changes below, so that you can bring things back and forth between school and home. This will be particularly crucial for demos of class projects.

Squeak on Linux...

...on the instructional Linux servers

I discourage you from using the instructional Linux servers, as running an entire Squeak environment for many users on the servers will probably overload them. However, if you want to try out Linux Squeak, then:

  1. Set up your X window server and login to the Linux boxes.
  2. Make a subdirectory for squeak in your home directory, and cd into it.
  3. Download the appropriate version of Squeak (including the architecture-specific files, the .image file, the .changes file, and the sources file) using your method of choice (wget or netscape will work). Extract the archive(s) using tar and gzip.
  4. Run ./squeak &

Audio will not work (X servers do not currently transmit audio over the network).

...on your own Linux machine

Instructions are as above, but obviously you do it on your own machine, not on the servers. Squeak will run substantially faster, and audio will probably work (although Squeak tries to monopolize your sound card, so you may want to disable sound).

Using Squeak

The Guzdial book, starting in Chapter 2, describes the Squeak environment pretty well. However, it takes a while to get into the details of the environment, so here's a quick start guide to getting all the pretty Squeak garbage out of the way so that you can code:

About mouse buttons

Here are color-to-button mappings for (Also on the bottom of p. 42 in the Guzdial book).


[Mac button mappings]


[Windows button mappings]


(or any 3-button mouse)
[Unix button mappings]

I will refer to mouse buttons by color throughout this document.

OK, how do I code?

Note: the following is taken more or less directly from Guzdial section 2.4. You may find his more verbose instructions (with illustrations) more helpful, or you may find them just verbose. Compare and see.

  1. Red-click on the Squeak desktop.
  2. Select "open..." -> "mvc project". A window with a name like "Unnamed1" should pop up; this is a like an icon for your project window.
  3. You should rename this project to something like "Yourname-Coding" by clicking on the name in the title bar.
  4. Now, red-click on the window and enter it. Your desktop, and all the Squeak garbage, should be cleared away. This is your new project.
  5. Red-click your project desktop.
  6. Select "open..." -> "workspace". A Workspace window will pop up. You can type code into this window.
  7. To execute a statement, select a chunk of code (or place your text cursor directly after an expression or statement) and press Alt-d (Command-d on Macs). For example, try executing the following:
        x := 3 + 4.
  8. To evaluate an expression and print the result, do the same as the above, and then press Alt-p (Command-p on Macs). Try selecting "3 + 4" in the above expression and printing it.
  9. To leave your project, red-click on the desktop and chooose "previous project". This should return you to the Squeak root desktop.

How do I define my own classes and methods?

You can actually do this from the workspace, but you don't want to. Instead, use the system browser:

  1. Enter the project you created above.
  2. Red-click on the Squeak desktop.
  3. Select "open..." -> "browser". A "System Browser" window should pop up.
  4. Yellow-click in the upper-left-most-panel.
  5. Select "add item..." and type in a category name. Your name will serve fine for this example. This creates a new class category.
  6. Click on your new category name. The bottom pane will now contain something like the following:
    Object subclass: #NameOfClass
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Keunwoo'
    In general, when you click on a class category, a fresh class template will appear in the bottom browser pane.
  7. Edit #NameOfClass to be something, like #Foobar
  8. Type Alt-s (Command-s on Mac) to "accept" the new Class. A "Foobar" class should appear in the second pane at the top.
  9. Red-click on "-- all --" in the third pane. Text resembling the following should appear:
    message selector and argument names
        "comment stating purpose of message"
        | temporary variable names |
    "-- all --" is a method category. In general, when you click on a method category, a fresh method template will appear in the bottom browser pane.
  10. Create a simple method like the following:
    showMe: aValue for: numTimes
        "Prints aValue to the Transcript numTimes."
        numTimes timesRepeat: [ Transcript show: aValue; cr ].
    Type Alt-s to accept this method. Fix any typos you made.
  11. Red-click on the Squeak desktop and "open..." -> "transcript". (Alternatively, type "Transcript show." in a Workspace and Alt-d it.) A window named "Transcript" should show up; this is a little like "standard output" in a more traditional environment.
  12. Go to your Workspace (or open a new one).
  13. Type the following code:
    x := Foobar new.
    x showMe: 'hi' for: 5.
    and Alt-d it.

That's it for the basics of creating classes, creating methods, and running code. Refer to Guzdial or the Squeak documentation (UIUC mirror) for further information.

Saving your work

Because Squeak is such an insular environment, saving your work and sharing it with others can be a bit of a hassle. There are many ways to save your work, and they are appropriate in different situations...

To save your whole system, including all your changes

Red-click on the Squeak desktop. Select "save". Your system's "image" will be saved in the Squeak directory. If you start Squeak again from that system image, you will recover the entire environment, including any source code changes you have made.

Image files actually deserve some more comment, and you should definitely read the discussion of them at the beginning of Guzdial 2.4. For the purposes of this class, you probably want to create your own image, leaving the old system image alone. To do this, red-click the Squeak desktop and select "save as..." and type a new name---e.g., keunwoo.image.

The next time you run Squeak, pass it the name of the image at the command line:

./squeak keunwoo.image

In Windows, you can do this by dragging and dropping your image file onto the Squeak executable. Your system image will be recovered from this file.

Do not lose or delete your system image! All your work is stored in this image. However, if you create your own image/changes files, you probably should delete the original Squeak system image and changes files (e.g. Squeak-2.7.image and Squeak-2.7.changes) in order to save space in your home directory.

By the way, if you want to transport your whole system from one machine to another, then make sure you copy both the .image file and its corresponding .changes file. For the example above, I would copy both keunwoo.image and keunwoo.changes.

To save an individual class to a file

There are two easy ways:

Either way, a text file in Macintosh-format (grrr!) will appear in the directory in which you launched Squeak.

If you want to read a file that has been "filed out", red-click the Squeak desktop and "open..." -> "file list". A very ugly typical graphical file browser window will pop up. Red-click on file names in the upper-right panel, then yellow-click to bring up the context menu for files. If you select "fileIn", you will be able to read a .st (SmallTalk) file as code.

Saving and loading changes from "change sets"

Filing out individual classes or class categories only goes so far. You can group larger sets of changes into a "change set", which can then be filed out as a file with the .cs extension.

There are lots of ways to group changes into a change set, but what you probably want to do most is to save all of a given project's changes to a change set, and load those changes somewhere else.

Saving a project's changes as a change set

Assuming you have a project named "Keunwoo-Coding", you can create a change set based on all the changes in this project as follows:

  1. Red-click on the Squeak desktop.
  2. Choose "Changes..."
  3. Choose "Simple change sorter". A new change sorter window will pop up.
  4. In the window's upper left pane are a list of "change sets" that you can examine. Each project on the Squeak desktop has one change set associated with it. Scroll up or down until you find the change set associated with your project---in this example, "Keunwoo-Coding".
  5. Red-click on the name of your project. A list of changed classes should appear in the upper right pane. You can examine changes you've made to those classes by clicking on them.
  6. To file out all changes in a project, red-click on the project name to select it; then, yellow-click the project name and select "fileOut".
  7. A file named "Keunwoo-Coding.cs" will appear in the current directory.
Loading a change set into Squeak
  1. Red-click on the Squeak desktop. Select "open..." -> "file list".
  2. Use the file list to find the change set file, e.g. "foo.cs".
  3. Red-click on the change set file (in the upper-right pane) to select it. Then, yellow-click the file to bring up its menu; select fileIn.
Notes about change sets

Be warned that you can make bad things happen while browsing around with change sets: I brought up a window and tried to examine a class that no longer existed, resulting in a big chain of errors that eventually crashed the window.

Changes that are loaded from a change set are treated like any other changes you make; if you want them to be logged under a project, open that project and fileIn the change set while inside that project. Otherwise, they will be logged as an "UnnamedN" change set, where N is the number of unnamed change sets currently in your image.

Comments to
Last modified: Wed Feb 18 16:05:04 PDT 2004