Basic Squeak Usage


Squeak is a neat implementation of the Smalltalk programming language. Interaction with the GUI is done with a mouse and the keyboard. Everything on screen is an object, whether it is a window, text, a button, or a graphical object.
To begin, left click on the desktop and select 'open...' A basic project will require a workspace, browser, and a transcript, so open one of each.

The System Browser is your main programming interface to Squeak. The top left-most pane is a list of grouped system classes. By control-clicking in this pane (or the middle mouse button depending on your system) we get a menu which lets us add item... Select this option, and enter an appropriate name for your group of classes. I'll use NU-Stuff.

The bottom pane is where you will enter your class definitions and methods. This definition creates a subclass of Object called SimpleCounter, with no instance or class variables.
Object subclass: #SimpleCounter
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'NU-Stuff'

To accept this definition into Squeak, press Alt-s to save the text. You can also save your work by ctrl-clicking in the pane, and selecting accept (s). Your first time through, Squeak may prompt you for your initials for it's version tracking.

We want to create a class (not an instance) SimpleCounter which will:

Click on the class button in second pane from the left. Your definition will change a little, but it's not a problem. We will need one instance variable, count, and the three methods. If you add the instance variable, your definition should now look like this:

Save this again. Squeak may warn you that you are changing an existing class in the system, but you are just changing something you already created; click on yes.

Now it's time to add the methods to this class. The third pane over on the top is a list of different groups of methods for this class. Right now, it should just say no messages. The bottom pane should change again if you click on no messages. Enter the following three methods into the bottom pane, one at a time, and press alt-s after each one.

Tip 1: To paste from the clipboard/buffer, use alt-v. To copy to the clipboard/buffer, use alt-c
Tip 2: Assignment in Squeak is done with either a ':=', as in Pascal, or with a '_', which is interpreted as a '<-' in Squeak.

new
    count := 0.
    ^ count

inc
    count := count + 1.
    ^ count

val
    Transcript show: count asString.
    ^ count

Let's try to create an instance of our class and start sending it messages. Switch to the workspace, and enter the following lines:

A := SimpleCounter new.
A inc.
A inc.
A val.

To run these commands, highlight them with the mouse, and press alt-d. You can also ctrl-click, and select do it (d) from the menu.

The Transcript should display the value of our counter, in this case a 2. Try playing around with this example a little to get a feel for how Squeak works. It is different from most programming environments, but it is quite intuitive and easy to use once you get used to it.


Back to Index page.