- This part of the assignment entails completing various tasks in
the Squeak environment. The environment is a little different under
Windows/Mac/Unix. The basic difference is the number of buttons on
the mouse which changes the menus-to-button relationship. The various
menus can be found using the different buttons if available and by
going to the slider and clicking when your pointer becomes the menu
icon. Notice to move the slider up/down/drag is controlled by where
you place the pointer and not the button. Some of the button
information might be different for your OS so adjust appropriately.
- Practice using the mouse to see the windows that come with Squeak
and read the included instructions. To open the windows that show up
as rectangles with names click the box in the right corner of the
rectangle. The course web page has a link to the Squeak web page which
in turn has pointers to Smalltalk information. Note: the best way to
learn Smalltalk is to use the system browser to look at existing code
that is part of the system.
- Go to the "Welcome to..." window and besides reading the
information, try executing some of the sample objects.
To execute the sample you need to highlight the object and method call
(i.e. Display restoreAfter: [WarpBlt test1])
by pressing the left mouse button and dragging. Then press the
middle mouse button to get up the menu. From the menu you can then
"do it", "print it", copy, paste, ... NOTE: using copy you can copy
things out of Squeak and into emacs or another editor.
- Open a browser, a workspace, and a file list. This can be done
using the middle mouse button on the gray background and selecting
open. You will need to select update from the menu to see changes of
a "file in" within your system browser.
- Try using inspect to look at an instance of an object.
- From the browser look at class methods and instance methods.
Constructors for an instance are examples of class methods. Instance
methods are methods that can be called on the object instance/active object.
- To assign an object to a variable use the _ which appears as <-
- To return a value from a method use the ^ which appears as <-
rotated clockwise 90 degrees (i.e. up arrow that is too hard to put
into this document).
Problems on ugrad computers and ways around it.
- I think I have found the solutions to some of our problems. If
you use this on your own computer you will probably not have these
problems. The SqueakV1.sources file is missing but should be added soon.
- Filling in a file - It appears that the system needs to write some
information to the directory from which you file in, so the file being
filed in must be in your directory or you can make a link.
- Filling out changes - It is similar to the above problem. The
information filed out goes to the directory where your image file is
located which in the case of the ugrad lab is not writable. The
solution is to create links like the ones below. I know the
information below is very detailed but I was not sure the Unix
background of all the students.
cd ~
mkdir CS4448
cd CS4448
ln -s /tools/ugrad/squeak/squeak .
ln -s /tools/ugrad/squeak/Squeak1.23.changes .
ln -s /tools/ugrad/squeak/Squeak1.23.image .
ln -s /tools/ugrad/squeak/SqueakV1.sources .
ln -s ~griff/CS4448/hw2.example.st .
Creating a new class and category
- Create a new category - go to the system browser and choose the
first of the sub-windows. Press the middle mouse button and select "add
item".
- Create a new class - select the appropriate category where you
want the class added. Then make sure no class is selected in the
second window. If one is selected then select it again to toggle the
selection off. When no class is selected you will see the code below
in the large bottom window.
Object subclass: #NameOfClass
instanceVariableNames: 'instVarName1 instVarName2'
classVariableNames: 'ClassVarName1 ClassVarName2'
poolDictionaries: ''
category: 'Graphics-Primitives'
Modify this code to create your new class like the one below.
Object subclass: #Point
instanceVariableNames: 'x y '
classVariableNames: ''
poolDictionaries: ''
category: 'Graphics-Primitives'
- Use the third window to create new categories just like you did in
the first window.
- In the fourth window you can create the methods. This window
works like the second window but with the code below instead.
message selector and argument names
"comment stating purpose of message"
| temporary variable names |
statements
Modify this code to create your new method. For example + in the
arithmetic classification.
+ delta
"Answer a Point that is the sum of the receiver and delta (which is a
Point or Number)."
| deltaPoint |
deltaPoint _ delta asPoint.
^x + deltaPoint x @ (y + deltaPoint y)
File in and out code
- To "file in" code go to the file list window. Select the file you
wish to read in and then using the middle mouse button select fileIn.
What ever was parsed is now part of the system and changes, new
methods, classes, etc. can now be viewed in the system browser window.
- To "file out" code select the category, class, method category,
method that you wish to file out. Using the middle mouse button
select fileOut. Everything under that level will be
filled out so selecting category is a good way to file out a new
project you created and stored in its own category.
Triple Class
In C
structure definitions for abstract data type
struct triple_type {
int x;
int y;
int z; } triple
triple.x=5, triple.y=9, ..
In C++
class Triple{
private:
int x;
int y;
int z;
public:
int set_x(int new_x_value) { x=new_x_value;
return x; }
int get_x() {return x;}
}
or
class Triple : public System_Triple {
int set_y(int new_y_value) { System_Triple::set_y(new_x_value);
return System_Triple::get_y(); }
}
Adam Jonathan Griff,
computer@griffmonster.com
Copyright © University of Colorado. All rights reserved.
Revised: January 21, 1998