Lab 0 - Introduction to Squeak


Don't forget that lab 0 and lab 1 go together as a unit

Overview

In this lab, you will be introduced to the Squeak Smalltalk programming system. You will learn how to start Squeak, how to use Squeak's Workspace and Transcript, and then use them to perform a set of simple (for Squeak!) tasks:

By the end of this lab you should:


Step Zero: Starting Squeak

The First Time You Run Squeak

Do the following to get set up:

  1. If you haven't already, create a directory in your network home directory (drive H:) to keep your 2803 files in, for instance H:cs2803.
  2. Using NT Explorer or My Computer, open S:\Apps\Squeak
  3. Copy Squeak2.5.image copy Squeak2.5.changes into the directory you made above. To reduce confusion, you can rename the files to reflect that they are your image and changes file, as opposed to the stock 2.5 image and changes file. BE SURE TO MAKE THE IMAGE AND CHANGES FILE NAMES MATCH!. For instance, you would make the following two copies:
    • S:\Apps\Squeak\Squeak2.5.image --> H:\cs2803\JohnDoe.image
    • S:\Apps\Squeak\Squeak2.5.changes --> H:\cs2803\JohnDoe.changes

To Run Squeak (Every Time)

Here is the (convoluted) procedure for running Squeak on the NT's:

  1. Copy your image and changes file from your home directory to C:\Temp
  2. Double click on SqueakXXX.image
  3. If a window appears asking you what to open the file with.. Choose browse and select s:\apps\squeak\squeak.exe
  4. Check the box next to "Always use this program to open this type of file" if you want Windows to always use Squeak to open .image files
  5. When you are done and have saved and quit Squeak, copy your image and changes file back to your home directory, and delete everything you have put in C:\Temp.

WARNING: Do not access another student's image and/or changes file that have been left in a temp directory. Doing so will be considered a violation of the honor code.

If you haven't already, go ahead and start up Squeak on your personal image.


Step One: Basic Usage: The Mouse

Smalltalk uses all three buttons of the mouse extensively. Within a Smalltalk window, the buttons work as follows:

Also, you can left click on the gray background of the Squeak window and get a system-wide menu with options to create new windows and to exit the systems.

Try it now. Left click on the background, hold the button down, select "open", and select "open transcript". An orange window labeled "Transcript" should appear. Use the left button on the borders to shrink this window down a little, and then move it to the bottom of the screen out of the way. This window is where your output will appear later on.

As a second test, left click on the background, hold the button down, and select "save". The cursor should change for a couple of seconds as Squeak saves a current version of your image; if you get an error message, then you are probably using an image on a network drive, instead of in C:\Temp; exit Squeak (without saving changes), and try the above directions again.


Step Two: fileOut and fileIn

Exporting a class definition from Squeak is known as performing a fileOut. Similarly, importing a class definition into Squeak is known as performing a fileIn. You need to open a System Browser in order to do either of these actions. Click the left button on the gray background area, select "open", and select "open browser". A new window should appear, which is divided into 5 subwindows ("panes"): four panes across the top and one big one at the bottom.

The leftmost pane is a list of categories. Each category contains a bunch of related classes. Scroll down the list until you reach the Music-Scores category and select it. You should see a number of classes listed in the pane immediately to the right: Select AmbientEvent and then right-click in the same pane. Choose "fileOut" from the Menu. The cursor will change briefly to a pencil, indicating that Squeak is saving a copy of the class definition. In addition, the Transcript will show the name of the class you just exported.

Use Explorer to look at the contents of your cs2803 directory. There will be a new file named AmbientEvent.st. By default, when you fileOut a class from Squeak, the class definition is saved in a file named 'class name.st'. This will be the primary way that you save out the code that you will be writing.

(Note: You can ignore the very last part of this paragraph. There is no ButtonMorph.st file to file in. Sorry for any confusion this has caused - Rodney)
Importing a file is simple as well. You'll use this procedure when you are given example code to use in future labs. In order to avoid corrupting the Squeak image you're working with, make sure you don't change the ButtonMorph.st file. Left-click on the grey desktop and choose "open..." and then "file list..." from the resulting menu. You will then be shown a browser window containing the contents of your cs2803 directory. Select ButtonMorph.st, then right-click and choose fileIn from the menu. Squeak will then import the class definition into its class library.


Step Three: WWW Browsing with Scamper

In this part you will use Squeak's built-in WWW browser, Scamper. Go to the Workspace window and type Scamper openAsMorph.. Select the text you just typed and do it. You will see the initial Scamper window open and see that the default first page it opens is http://minnow.cc.gatech.edu/, the Squeak information page. Make a note of this page's address; you'll want to take a look at this information to get the most out of using Squeak. The second pane from the top contains the URL of the currently loaded page - you can type into this pane to open any page you like. Try it! If you right-click over the page, you'll get a menu that offers choices similar to the right-button menu in Netscape Navigator. Experiment with the "view source" and other choices. Also, look at the Transcript window after you load a page and you will see Scamper's output while it loads. When you're done experimenting with Scamper, close its window by clicking in the open square on the titlebar.


Step Four: Reading email with Celeste

Now you'll use another component built in Squeak to read email. The name of this component is Celeste. Celeste uses a local "mail database" to handle email, but it can also send and retrieve email from a different machine in the same manner as Netscape Messenger or Eudora.

In order to start Celeste, enter Celeste openOn: 'mydb' in the Workspace and do it. You'll be asked whether you want to create a new mail database named "mydb"; answer yes. When you do, the main Celeste window is displayed. The Celeste window is divided into 3 rows of panes. The top row is actually a set of buttons that allow you to filter any displayed messages by a certain string. There also are buttons for Replying, Forwarding, and Deleting a mail message. The middle row contains two list panes, the left containing categories of email messages (really just folders) and the right containing a list of the mail message headers in each category. The bottom "row" is simply one large pane where any currently selected messages will be displayed. If you right-click in each of the categories, message headers, or message panes, you'll see a context-sensitive menu containing different commands for each pane.

Now you'll use Celeste to read your email. To do this, you have to first tell Celeste where to retrieve your mail from. In the the categories pane, choose "set POP server" from the right-button menu. Enter the POP server name of the machine on which you read your email in the dialog box (for example, pop.prism.gatech.edu or gaia.cc.gatech.edu). You also must tell Celeste what your POP username will be, so that it can retrieve your mail from the mail server. Choose "set POP username" from the right-button menu and enter the username you use to login to the machine whose name you entered above (for pop.prism.gatech.edu, use your prism username). To get your mail messages, right-click in the categories pane and choose "fetch mail". Celeste will use the POP protocol to retrieve the messages in your mailbox from machine you indicated. When this is complete, you will see your email messages listed in the message headers pane. You can read each of them by selecting each header in turn; their bodies will be displayed in the bottom pane.

Don't worry that Celeste has made permanent changes to your mailbox. By default, Celeste is configured to only make copies of the messages in your mailbox. You'll be using Celeste again for the final part of the lab, so don't close it. If you want to minimize it, you can click in top right square on the Celeste titlebar.


Step Five: Your First Class and Method

Now we're going to use the System Browser to create your first Squeak class. Either find the System Browser window you used in Step Two or open a new one as you did in Step Two. Here's a picture of what the browser should look like.

Press the right mouse button over the class categories list and choose the option to create a new category. Name this category Muppet Classes. Once you've done this, a new category will be inserted in the class categories list. Select this new category and you'll see that the class browser presents you with a template for defining a new class. In this template, you simply replace the pieces of the template that you want and leave the rest. Click in this template and replace NameOfClass with Muppet. Right-click and choose Accept from the menu and Squeak will compile your new class into the system.

Now that you've created a class, let's exercise it a little. When you Accepted your changes above, Squeak added the class to the list of classes in the Muppet Classes category. Since your Muppet class is a subclass of Object, it already knows how to do some things. For example, bring up your Workspace window and enter the following code: kermit := Muppet new. Transcript show: kermit printString. Select this code and Do it, and look at your Transcript window. The Transcript window will read a Muppet, which is the default way Squeak prints objects.

Now you'll add a new method to your class. Select the Muppet class in the browser window and then the message category "no messages" in the message category window (look at the picture of the System Browser above if you've forgotten which is which). Squeak will give you another template to use - this one is for methods. You'll learn later how to do things with this template, but for this lab just replace all of the template with the following text: greet "Return a pre-defined greeting" Transcript show: 'Hello there!'. Be sure to include the quotation marks exactly as shown. Right click and Accept your work, and Squeak will add this method to the class.

Now pull up your Workspace window and enter the following code: kermit := Muppet new. kermit greet. Select this code and Do it, and you will see your object greet you on the Transcript.

In Step Two, you used the fileOut technique to save a Squeak class to a file. Use it again to save your Muppet class to a file. You'll use the text in this file as the material that you turn in for this lab. You'll turn it in by using Celeste to mail the file to the turnin mail address. In the Workspace window, type (FileStream oldFileNamed: 'Muppet.st') edit. and do it. You'll be shown the file editor. This is a text editor with some enhanced capabilities. If you right-click in the editor window you'll see a menu with lots of different choices. Use the mouse to select the entire contents of the file and choose "copy" from the right-button menu to copy the selected text to the Clipboard.


Step Six: Sending mail using Celeste

In the Celeste window, right-click in the message-headers pane (to the right of the category list). Choose "compose" from this menu. Celeste will ask you what your email address is, so that it can properly compose the message. Enter your email address. You'll then see the "Mister Postman" window. This window contains two panes. The top pane is simply a large Send button. The bottom pane is an editable text pane where you'll enter your message. You should see your own email address on the From: line. On the To: line, enter your TA's email addres. On the Subject: line, enter your name, section and the assignment name. Your subject line should then look like
Rodney Walker, Lab 0, Section A
Hit Enter twice for two blank lines. Now, paste the contents of the Clipboard into the message by typing Alt-V (note, not Control-V as in Windows). Now, you can hit the Send button to finish composing the message.

Celeste doesn't automatically send new messages. Look in the categories pane; there is a category called .tosend. that contains the message you just composed. You need to explicitly tell Celeste to send your email. In the categories pane, right click and choose "send queued mail". Celeste will ask for the name of your SMTP server, which is the server it will attempt to contact in order to send your mail. Enter gaia.cc.gatech.edu. You will see a brief progress message as Celeste contacts the mail server and sends your message, and then you'll be returned to the main Celeste window. Note that the ".tosend." category is now empty, and that your message is now in the "sent" category. If you like, you can look at the Transcript window and see the conversation that took place between the machine you're at and the mail server.

Important! - You'll be using email to turn in all or part of your solutions to the labs and assignments in this course. You can use whatever mail program you wish in order to send the mail, as long as you know how to make it send text without HTML or other encoding and without converting the text into an attachment. Celeste will work fine for this, so now you know you have at least one option.


Step Seven: Finishing up

Close the Celeste window by clicking in its close box at the left side of its titlebar. Do the same with the file editor window (it will ask you if you want to save changes, tell it no). You can then exit Squeak.

IMPORTANT: Be sure to delete mydb.* from the C:\TEMP directory of the computer on which you're working. These files contain your mail messages that Celeste downloaded from your mail server, and you'll want to remove them before you leave the computer.


Back to the top | Over to CoWeb