The windowing interface is built on top of guido van
rossums standard window package, and runs on top of systems
that support standard windows. These include X-11 and the
Macintosh.
When you start up the system, there will be a single
window titled ``workspace''. You can enter expressions in
the workspace, then select either the menu items ``do it''
or ``print it''. Both will evaluate the expression; the
latter, in addition, will print the result.
A number of other memu commands are also available.
These permit you to save the current image, exit the system,
or start the browser.
The browser is an interface permiting you to easily
view system code. Selecting a class in the first pane of
the browser brings up a second pane in which you can select
methods, selecting a method brings up a third pane in which
you can view and edit text. Selecting ``compile'' following
the editing of text will attempt to compile the method. If
no errors are reported, the method is then available for
execution.
July 7, 1994
- 3 -
_2. _E_x_p_l_o_r_i_n_g _a_n_d _C_r_e_a_t_i_n_g
This section describes how to discover information
about existing objects and create new objects using the Lit-
tle Smalltalk system (version three). In Smalltalk one com-
municates with objects by passing messages to them. Even
the addition message + is treated as a message passed to the
first object 5, with an argument represented by the second
object. Other messages can be used to discover information
about various objects. The most basic fact you can discover
about an object is its class. This is given by the message
ccccllllaaaassssssss, as in the following examples:
> 7 class
Integer
> nil class
UndefinedObject
Occasionally, especially when programming, one would
like to ask whether the class of an object matches some
known class. One way to do this would be to use the message
==== ====, which tells whether two expressions represent the same
object:
> ( 7 class = = Integer)
True
> nil class = = Object
False
An easier way is to use the message iiiissssMMMMeeeemmmmbbbbeeeerrrrOOOOffff::::;
> 7 isMemberOf: Integer
True
> nil isMemberOf: Integer
False
Sometimes you want to know if an object is an instance
of a particular class or one if its subclasses; in this case
the appropriate message is iiiissssKKKKiiiinnnnddddOOOOffff::::.
> 7 isMemberOf: Number
False
> 7 isKindOf: Number
True
All objects will respond to the message ddddiiiissssppppllllaaaayyyy by tel-
ling a little about themselves. Many just give their class
and their printable representation:
July 7, 1994
- 4 -
> 7 display
(Class Integer) 7
> nil display
(Class UndefinedObject) nil
Others, such as classes, are a little more verbose:
> Integer display
Class Name: Integer
SuperClass: Number
Instance Variables:
no instance variables
Subclasses:
The display shows that the class IIIInnnntttteeeeggggeeeerrrr is a subclass of
class NNNNuuuummmmbbbbeeeerrrr (that is, class NNNNuuuummmmbbbbeeeerrrr is the superclass of
IIIInnnntttteeeeggggeeeerrrr). There are no instance variables for this class,
and it currently has no subclasses. All of this information
could be obtained by means of other messages, although the
ddddiiiissssppppllllaaaayyyy form is the easiest. [ Note: at the moment printing
subclasses takes a second or two. I'm not sure why.]
> List variables display
links
> Integer superClass
Number
> Collection subClasses display
IndexedCollection
Interval
List
About the only bit of information that is not provided when
one passes the message ddddiiiissssppppllllaaaayyyy to a class is a list of
methods the class responds to. There are two reasons for
this omission; the first is that this list can often be
quite long, and we don't want to scroll the other informa-
tion off the screen before the user has seen it. The second
reason is that there are really two different questions the
user could be asking. The first is what methods are actu-
ally implemented in a given class. A list containing the
set of methods implemented in a class can be found by pass-
ing the message mmmmeeeetttthhhhooooddddssss to a class. As we saw with the mes-
sage ssssuuuubbbbCCCCllllaaaasssssssseeeessss shown above, the command ddddiiiissssppppllllaaaayyyy prints this
information out one method to a line:
> True methods display
#ifTrue:ifFalse:
#not
A second question that one could ask is what message
July 7, 1994
- 5 -
selectors an instance of a given class will respond to,
whether they are inherited from superclasses or are defined
in the given class. This set is given in response to the
message rrrreeeessssppppoooonnnnddddssssTTTToooo. [ NOTE: again form some reason I'm not
sure of this command seems to take a long time to execute ].
> True respondsTo display
#class
#==
#hash
#isNil
#display
#=
#basicSize
#isMemberOf:
#notNil
#print
#basicAt:put:
#isKindOf:
#basicAt:
#printString
#or:
#and:
#ifFalse:ifTrue:
#ifTrue:
#ifFalse:
#not
#ifTrue:ifFalse:
Alternatively, one can ask whether instances of a given
class will respond to a specific message by writing the mes-
sage selector as a symbol:
> String respondsTo: #print
True
> String respondsTo: #+
False
The inverse of this would be to ask what classes con-
tain methods for a given message selector. Class SSSSyyyymmmmbbbboooollll
defines a method to yield just this information:
> #+ respondsTo display
Integer
Number
Float
The method that will be executed in response to a given
message selector can be displayed by means of the message
vvvviiiieeeewwwwMMMMeeeetttthhhhoooodddd::::
July 7, 1994
- 6 -
> Integer viewMethod: #gcd:
gcd: value
(value = 0) ifTrue: [ |^ self ].
(self negative) ifTrue: [ |^ self negated gcd: value ].
(value negative) ifTrue: [ |^ self gcd: value negated ].
(value > self) ifTrue: [ |^ value gcd: self ].
|^ value gcd: (self rem: value)
Some Smalltalk systems make it very difficult for you
to discover the bytecodes that a method gets translated
into. Since the primary goal of Little Smalltalk is to help
the student to discover how a modern very high level
language is implemented, it makes sense that the system
should help you as much as possible discover everything
about its internal structure. Thus a method, when presented
with the message ddddiiiissssppppllllaaaayyyy, will print out its bytecode
representation.
> Char methodNamed: #isAlphabetic ; display
Method #isAlphabetic
isAlphabetic
|^ (self isLowercase) or: [ self isUppercase ]
literals
Array ( #isLowercase #isUppercase )
bytecodes
32 2 0
129 8 1
144 9 0
250 15 10
9 0 9
32 2 0
129 8 1
145 9 1
242 15 2
245 15 5
241 15 1
Bytecodes are represented by four bit opcodes and four
bit operands, with occasional bytes representing data (more
detail can be found in the book). The three numbers written
on each line for the bytecodes represent the byte value fol-
lowed by the upper four bits and the lower four bits.
If you have written a new class and want to print the
class methods on a file you can use the message ffffiiiilllleeeeOOOOuuuutttt::::,
after first creating a file to write to. Both classes and
individual methods can be filed out, and several classes
and/or methods can be placed in one file. [ NOTE - file out
doesn't work yet ].
July 7, 1994
- 7 -
> f <- File new
> f name: 'foo.st'
> f open: 'w'
> Foo fileOut: f
> Bar fileOut: f
> Object fileOutMethod: #isFoo to: f
> f close
The file ``newfile'' will now have a printable representa-
tion of the methods for the class Foo. These can subse-
quently be filed back into a different smalltalk image.
> f <- File new
> f name: 'foo.st'
> f open: 'r'
> f fileIn
> 2 isFoo
False
Finally, once the user has added classes and variables
and made whatever other changes they want, the message
ssssaaaavvvveeeeIIIImmmmaaaaggggeeee, passed to the pseudo variable ssssmmmmaaaallllllllttttaaaallllkkkk, can be
used to save an entire object image on a file. If the writ-
ing of the image is successful, a message will be displayed.
> smalltalk saveImage
Image name? newimage
image newimage created
>
Typing control-D causes the interpreter to exit.
When the smalltalk system is restarted, an alternative
image, such as the image just created, can be specified by
giving its name on the argument line:
st newimage
Further information on Little Smalltalk can be found in
the book.
_3. _N_e_w _M_e_t_h_o_d_s, _N_e_w _C_l_a_s_s_e_s
_3._1. _S_t_d_i_n/_S_t_d_o_u_t _I_n_t_e_r_f_a_c_e
New functionality can be added using the message
aaaaddddddddMMMMeeeetttthhhhoooodddd. When passed to an instance of CCCCllllaaaassssssss, this mes-
sage drops the user into a standard Unix Editor. A body for
a new method can then be entered. When the user exits the
July 7, 1994
- 8 -
editor, the method body is compiled. If it is syntactically
correct, it is added to the methods for the class. If it is
incorrect, the user is given the option of re-editing the
method. The user is first prompted for the name of the
group to which the method belongs.
> Integer addMethod
... drop into editor and enter the following text
% x
|^ ( x + )
... exit editor
compiler error: invalid expression start )
edit again (yn) ?
...
In a similar manner, existing methods can be editing by
passing their selectors, as symbols to the message eeeeddddiiiitttt----
MMMMeeeetttthhhhoooodddd::::.
> Integer editMethod: #gcd:
... drop into editor working on the body of gcd:
The name of the editor used by these methods is taken
from a string pointed to by the global variable _e_d_i_t_o_r.
Different editors can be selected merely by redefining this
value:
editor <- 'emacs'
Adding a new subclass is accomplished by sending the
message aaaaddddddddSSSSuuuubbbbCCCCllllaaaassssssss::::iiiinnnnssssttttaaaannnncccceeeeVVVVaaaarrrriiiiaaaabbbblllleeeeNNNNaaaammmmeeeessss:::: to the superclass
object. The the first argument is a symbol representing the
name, the second is a string containing the names of any