Worksheet 1A

An Introduction to the Squeak World



Based on Introduction to Squeak by Harry Porter
Version 1.0, 17 April 2001, and
Version 2.0, 20 May 2002 by Andrew P. Black,
black at cs.pdx.edu
Version 3.0, March 2003 by Amdrew P. Black most recently modified on 06-04-04

Getting Started

If you don't already have the Squeak system on a computer that you can use, download and install it now! Launch Squeak.

Using the Mouse

Smalltalk, from which Squeak is derived and with which it is still somewhat compatible, was designed assuming a three-button mouse. If your mouse has fewer buttons, you must press extra keys with the mouse button or buttons to simulate the mouse buttons that you are missing.

For platform independence, the mouse buttons are usually referred to by colors in the Squeak software and documentation. Consider buying a 2 or 3-button mouse; they are quite inexpensive, and make the Squeak world much more friendly. (They are pretty useful in many other applications too!) Software that comes with the mouse, or that is available on the Internet, will let you set up the buttons so that they do the right thing. (I highly recommend USB Overdrive for the Mac.)

Squeak also has some built-in options for customising the mouse and the meta keys on your keyboard. Try open >> preferencs from the world menu, and search for swap. The swapMouseButtons preference switches the yellow and blue functions.

The following chart shows what keys must be held down when mouse-clicking to simulate Squeak's buttons.

Symbolic
MacOS
Windows
3-button
Use
Red
Mouse button
Left-button
Left-button
Selecting, moving the insertion cursor
Yellow
Option-button
Right-button
Middle-button
Application-specific menus
Blue
-button
Alt-Left-button
Right-button
Window and graphics manipulation

My mouse also has a scrolling wheel. I have this set up so that "wheel up" maps to -upArrow (on my Macintosh) and "wheel down" maps to -downArrow. This lets me use the wheel to control scrolling in my Squeak windows.

One of the advantages of referring to the buttons by colors is that you may choose to map them to different physical buttons from those shown above. For example, if you are left-handed, you might choose to reverse the red and blue buttons. On my mouse, the middle button is actually the scrolling wheel. Because the yellow button is used very frequently, I prefer to put the yellow button on the right, and to put the blue button on the wheel in the middle.

Placing some colored labels on the mouse buttons will help your fingers to follow these directions.

The World Menu

Red-click outside of any window; you will see the world menu. Notice that most Squeak menus are not modal; you can leave them on the screen for as long as you wish by selecting keep this menu up. Do this. Also, notice that menus appear when you click the mouse, but do not disappear when you release it; they stay visible until you make a selection, or until you click outside of the menu. You can even move the menu around by grabbing its title bar.

Bring up the open... submenu and select workspace. You should get a grey-boardered window labeled Workspace.

Terminating and Restarting a Squeak Session

When you start Squeak for the first time, the Squeak Virtual Machine is loaded with an image file, which contains an initial set of objects, including a vast amount of pre-existing code and programming tools (all of which are objects). You will modify these objects during your Squeak session.

When you terminate Squeak, you will save a snapshot of your memory containing all of your objects. The next time you use Squeak, memory will be reloaded from this file and the state of the system will be exactly as you left it. The snapshot file will be named xxxxx.image, where xxxxx is something you will choose, like Tutorial.image. There will be a corresponding "changes" file, with a name such as Tutorial.changes.

Collapse or close unneeded windows

Each window has a title bar with a "close" icon (an x) in the upper left and a "collapse" icon in the upper right.

Workspaces

Graphics Demonstrations

Accessing Files

File Creation and Removal

Importing Code using file In

Using a System Browser

The System Browser is the main tool used to read and write code in Smalltalk. It is OK to have many System Browsers open at once. Normally, if you change code in one Browser, the changes will be visible in any other. (Preferences >> smartUpdating controls this).

Executing Code: Sending Messages to Objects

Paths are collections of points used to represent geometric shapes.

There are two ways to type the assignment operator. You may either type colon-equal (like Pascal) or you may use the left arrow, which in Squeak replaces the underscore character. In other words, type the _ key and see on the display.

Forms and Points

Paths

Morphs

What if you Crash Squeak?

It is quite possible to crash Squeak—as an experimental system, Squeak lets you change anything, including things that are vital to make Squeak work! For example, try Smalltalk := nil.

The good news is that you need never loose work, even if you crash and go back to the last saved version of your image,which might be hours old. This is because all of the code that you executed is saved in the changes file. All of it! That includes one liners that you evaluate in a workspace, as well as code that you add to a class while programming.

So here are the instructions on how to get your code back. There is no need to read this until you need it. But when you do need it, you'll find it here waiting for you.

In the worst case, you can use a text editor on the changes file, but since it is many megabytes in size, this can be slow. Squeak gives you better ways.

How to get your code back

Restart Squeak, and select help>>useful expressions from the world menu. This will give you a workspace full of useful expressions. The first three,

Smalltalk recover: 10000.
ChangeList browseRecentLog.
ChangeList browseRecent: 2000.

are most useful for recovery.

If you execute ChangeList browseRecentLog, you will be given an opportunity to decide how far back in history you wish to browse. Normally, it's sufficient to browse changes as far back as the last Snapshot. (You can get much the same effect by editing ChangeList browseRecent: 2000 so that the number 2000 becomes something else, using trial and error.)

One you have a recent changes browser, showing, say, changes back as far as your last snapshot, you will have a list of everything that you have done to Squeak during that time. You can delete items from this list using the yellow-button menu. When you are satisfied, you can file in what is left. It's a good idea to start a new change set, using the ordinary change set browser, before you do the file in, so that all of your recovered code will be in a new change set. You can them file out this change set.

One useful thing to do in the Recent changes browser is to remove doIts. Usually, you won't want to file in (and thus re-execute) doIts. But there is an exception. Creating a class shows up as a doIt. Before you can file in the methods for a class, the class must exist. So, if you have created any new classes, first file in the class creation doIts, then remove doIts and file in the methods.

When I am done, I like to file out my new ChangeSet, quit Squeak without saving the image, restart, and make sure that my new ChangeSet files back in cleanly.