Squeak Smalltalk:
A Quick Reference
Version 0.0, November 20, 1999, by Andrew C. Greenberg,
werdna@gate.net
Based on:
Smalltalk-80: The Language and
Its Implementation, Author: Adele Goldberg and David Robson
Squeak Source Code v. 2.6
and the readers of Squeak-L
Squeak site: http://www.squeak.org
Contents
Using Squeak: the Basics
Mousing Around
Squeak (and the Smalltalk-80 from which it was spawned) assumes a machine with a three-button mouse (or its equivalent). These buttons were referred to as "red," "yellow" and "blue." The red button was conventionally used for selecting "things," the yellow button was conventionally used for manipulating "things" within a view or window and the blue button was conventionally used for manipulating windows themselves. Conventions, of course, are not always followed and your mileage may vary.
Since many modern mice no longer have three buttons, let alone colored ones, various "mapping" conventions are used:
For uncolored three-button mice, the mapping is:
left-mouse -> red
middle-mouse -> yellow
right-mouse -> blue
Windows machines with three button mice can be made to conform with this mapping by right clicking the Windows titlebar of Squeak, and selecting "VM Preferences -> Use 3 button mouse mapping." Otherwise, for Windows machines, the mapping is:
left-mouse -> red
right-mouse -> yellow
alt-left-mouse -> blue
MacOS Systems generally have one mouse button. The mapping is:
mouse -> red
option-mouse -> yellow
cmd-mouse -> blue
System Menus
Squeak provides access to certain Smalltalk services through its system menus, some of which are depicted below:
The Main Menu. The leftmost window, sometimes called the "main menu," can be reached by clicking the red button while the mouse points to the background of a system project. From this menu, you can save the image and changes files, save them in files with a different name, and terminate execution of the Squeak virtual machine.
The Open Menu. Selecting "open..." from the main menu generates a menu providing access to many system tools, including system browsers, workspaces, transcripts and file lists.
The Help Menu. Selecting "help..." from the main menu generates a menu providing access to certain on-line help facilities as well as facilities for updating your current version of Squeak.
The Windows MenuSelecting "windows and flaps..." (or in the MVC GUI, just "windows...") from the main menu generates a menu providing access to services for manipulating system windows and (in Morphic only) flaps.
System Key Bindings
Applications that use standard Squeak text container widgets, including most System Browsers, Workspaces, File Lists and Transcripts, provide facilities for manipulating the text and providing access to other system functionality. Many of these facilities can be reached by using the red-button menus, but others are conveniently accessed using special keypress sequences. Of course, particular applications can use some, all or of none of these -- your mileage may vary.
In the following tables, a lower-case or numeric command "key" can be typed by simultaneously pressing the key and the Alt (or on MacOS systems, the Command key). Upper-case keys are typed by simultaneously pressing either Shift-Alt (or Shift-Cmd) and the indicated key, or Ctrl and the indicated key. Other special keypresses are indicated below in square brackets.
General Editing Commands
Key |
Description |
Notes |
z | Undo | Note |
x | Cut | Note |
c | Copy | Note |
v | Paste | Note |
a | Select all | Note |
D | Duplicate. Paste the current selection over the prior selection, if it is non-overlapping and legal | 1 |
e | Exchange. Exchange the contents of current selection with contents of the immediately previous selection | 1 |
y | Swap. If the selection has 0 characters, swap the immediately surrounding characters. If the selection has 2 characters, swap them. | Note |
w | Delete preceding word | Note |
Notes
- These commands concern and effect not only the current selection, but also the immediately preceding selection.
Search and Replace
Key |
Description |
Notes |
f | Find. Set the search string from a string entered in a dialog. Then, advance the cursor to the next occurrence of the search string. | Note |
g | Find again. Advance the cursor to the next occurrence of the search string. | Note |
h | Set Search String from the selection. | Note |
j | Replace the next occurrence of the search string with the last replacement made | Note |
A | Advance argument. Advance the cursor to the next keyword argument, or to the end of string if no keyword arguments remain. | Note |
J | Replace all occurrences of the search string with the last replacement made | Note |
S | Replacing all occurrences of the search string with the present change text | Note |
Cancel/Accept
Key |
Description |
Notes |
l | Cancel (also "revert"). Cancel all edits made since the pane was opened or since the last save | Note |
s | Accept (also "save"). Change the model associated with this window to reflect the current view. | Note |
o | Spawn. Open a new workspace containing the present contents of this pane, and then reset the present window to the preceding state (that is, cancel the present window). | Note |
Browsing and Inspecting
Key |
Description |
Notes |
b | Browse "it" (where "it" is a class name) | 1 |
d | Do "it" (where "it" is a Smalltalk expression) | 1 |
i | Inspect "it." Open an inspector on "it" (where "it" is a Smalltalk expression) | 1 |
m | Open a browser of methods implementing "it" (where "it" is a message selector) | 1,2 |
n | Open a browser of methods that send "it" (where "it" is a message selector). | 1,2 |
p | Print "it". Evaluate "it" and insert the results immediately after "it." (where "it" is a Smalltalk expression) | 1 |
B | Set the present browser to browse "it" (where "it" is a class name) | 1 |
E | Open a browser of methods whose source contain strings with "it" as a substring. | 1 |
I | Open the Object Explorer on "it" (where "it" is an expression) | 1 |
N | Open a browser of methods referencing "it" (where "it" is an identifier) | 1 |
O | Open single-message browser (in selector lists) | 1 |
W | Open a browser of methods whose selectors include "it" as a substring. | 1 |
Notes:
- A null selection will be expanded to a word or to the current line in an attempt to do what you want.
- For these operations, "It" means the outermost keyword selector in a large selection.
Special Conversions and Processing
Key |
Description |
Notes |
C | Open a workspace showing a comparison of the selection with the contents of the clipboard | Note |
U | Convert linefeeds to carriage returns in selection | Note |
X | Force selection to lowercase | Note |
Y | Force selection to uppercase | Note |
Z | Capitalize all words in selection | Note |
Smalltalk Program Data Entry
Key |
Description |
Notes |
q | Attempt to complete the selection with a valid and defined Smalltalk selector. Repeated commands yield additional selectors. | Note |
r | Recognizer. Invoke the Squeak glyph character recognizer. (Terminate recognition by mousing out of the window) | Note |
F | Insert 'ifFalse:' | Note |
T | Insert 'ifTrue:' | Note |
V | Paste author's initials | Note |
L | Outdent (move selection one tab-stop left) | Note |
R | Indent (move selection one tab-stap right) | Note |
[Ctl-return] | Insert return followed by as many tabs as the previous line (with a further adjustment for additional brackets in that line) | Note |
[shift-delete] | Forward delete character | Note |
Bracket Keys
These keys are used to enclose (or unenclose if the selection is already enclosed) the selection in a kind of bracket. As an aside, double clicking just inside any bracketed text selects the entire text.
Key |
Description |
Notes |
[Control-(] | Enclose within ( and ), or remove enclosing ( and ) | Note |
[ | Enclose within [ and ], or remove enclosing [ and ] | Note |
{ | Enclose within { and }, or remove enclosing { and } | Note |
< | Enclose within < and >, or remove enclosing < and > | Note |
' | Enclose within ' and ', or remove enclosing ' and ' | Note |
" | Enclose within " and ", or remove enclosing " and " | Note |
Special Keys for Changing Text Style and Emphasis
Key |
Description |
Notes |
k | Set font | Note |
u | Align | Note |
K | Set style | Note |
1 | 10 point font | Note |
2 | 12 point font | Note |
3 | 18 point font | Note |
4 | 24 point font | Note |
5 | 36 point font | Note |
6 | color, action-on-click, link to class comment, link to method, url. Brings up a menu. To remove these properties, select more than the active part and then use command-0. | Note |
7 | bold | Note |
8 | italic | Note |
9 | narrow (same as negative kern) | Note |
0 | plain text (resets all emphasis) | Note |
- | underlined (toggles it) | Note |
= | struck out (toggles it) | Note |
Cmd-shift | Cmd-shift | Note |
_ (aka shift -) | negative kern (letters 1 pixel closer) | Note |
+ | positive kern (letters 1 pixel larger spread) | Note |
Squeak Smalltalk Syntax: the Basics
Keywords
Keyword |
Description |
nil | The singleton element of Class UndefinedObject |
true | The singleton element of Class True |
false | The singleton element of Class False |
self | The receiver of the "current" message |
thisContext | The active context, that is, the "currently executing" MethodContext or BlockContext. |
homeContext | If the active context is a MethodContext, the home context is the same context. If the active context is a BlockContext, the home context is the contents of the home field of the active context. |
Identifiers
letter (letter | digit )*
-
Smalltalk identifiers, etc. are case-sensitive.
- It is a Smalltalk convention for identifiers (instance and
temporaries) of several words to begin with a lower case character,
and then capitalize subsequent words. (e.g.
thisIsACompoundIdentifier).
- Certain identifiers, for example, globals class variables, are by
convention initially capitalized. (e.g. ThisIsProbablyAClassVariable)
Comments
"a comment comprises any sequence of characters, separated by
double quotes"
"comments can include the 'string' character"
"and comments can include embedded double quote characters
by ""doubling"" them"
"comments can span many
many
lines"
Literals (Constant Expressions)
Numbers (Instances of Number)
Decimal integer: 1234, 12345678901234567890
Octal integer: 8r177, 8r1777777777777777777777
Hex integer: 16rFF, 16r123456789ABCDEF012345
Arbitrary base integer: 2r1010 ==> 10
Integer with exponent: 123e2 ==> 12300, 2r1010e2 ==> 40
Float (double precision): 3.14e-10
Arbitrary base float: 2r1.1 ==> 1.5
Float with exponent: 2r1.1e2 ==> 6.0
- Squeak supports SmallInteger arithmetic (integers between -2**30
and 2**30-1) with fast internal primitives.
- Squeak supports arbitrary precision arithmetic seamlessly
(automatically coercing SmallInteger to LargePositiveInteger and
LargeNegativeInteger where appropriate), albeit at a slight cost in
speed.
- Squeak supports several other types of "numeric" values, such as
Fractions (arbitrary precision rational numbers) and Points. While
these are not built-in syntactic objects, they are naturally
expressed as operations on built-in operations. ( "2/3" and "2@3",
respectively)
- While numbers themselves may be represented in many radices, the radix specification and the exponent specification is always expressed in base 10.
Characters (Instances of Character)
$x "A character is any character (even unprintable ones),
preceded with a dollar sign"
$3 "Don't be shy about characters that are numeric symbols"
$< "or symbols"
$$ "or even the dollar sign"
Strings (Instances of String)
'a string comprises any sequence of characters, separated by
single quotes'
'strings can include the "comment" character'
'and strings can include embedded single quote characters
by doublin'' them'
'strings can contain embedded
newline characters'
'' "and don't forget the empty string"
- A string is very much like ("isomorphic to") a array consisting
only of characters. Indexing a string answers characters at the
corresponding index.
Symbols (Instances of Symbol)
#'A string preceded with a hash sign is a Symbol'
#orAnyIdentifierPrefixedWithAHashSymbol
#orAnIdentifierEndingWithAColon:
#or:several:identifiers:each:ending:with:a:colon:
#- "A symbol can also be a '-' or any special
character preceded with a hash"
#+< "or any pair of special characters preceded with a hash"
- Symbol is a subclass of String, and share, in large part, the
same internal representation. The primary difference between a
symbol and a string is that all symbols comprising the same
characters have the same instance. Two different string instances
can both have the characters 'test one two three', but every instance
of a symbol having the characters $'test one two three' is the same
instance.
- The "unique instance" property of symbols mean that they can be
efficiently compared. Equality (=) is the same as identity (==).
- "Identifier with colon" Symbols (e.g. #a:keyword:selector:) are
often referred to as keyword selectors, for reasons that will be made
clear later.
- "Single or dual symbol" Symbols (e.g. #++) are often referred to
as binary selectors.
- The following are permissible special characters: +/\*~<>=@%|&?!
- Note that $-- is not a symbol (or a binary selector). On the
other hand, $'--' is a symbol (but not a binary selector).
Constant Arrays (Instances of Array)
#( 1 2 3 4 5 ) "An array of size 5 comprising five
Integers (1 to 5)"
#( 'this'. #is. $a. #'constant'. array ) "An array
of size 5 comprising a String ('this'), a Symbol (#is), a Character
($a) and two Symbols (#constant and #array)."
#( 1 2 ( 1 #(2) 3 ) 4 ) "An array of size 4
comprising two Integers (1 and 2), an Array of size 3, and another
Integer (4)."
#( 1 + 2 ) "An array of size 3 comprising 1, #+,
and 2. It is not the singleton array comprising 3."
- Constant arrays are constants, and their elements must therefore
be constants. "Expressions" are not evaluated, but are generally
parsed as sequences of symbols as in the example above.
- Constant arrays may contain constant arrays. The hash sign
character for internal constant arrays is optional.
- Identifiers and sequences of characters in constant arrays are
treated as symbols
- Indexing is generally 1-based.
Assignments
identifier expression
identifier := expression
foo 100 factorial
foo bar 1000 factorial
- The identifier (whether instance variable, class variable,
temporary variable, or otherwise) will thereafter hold a pointer to
the object answered by the expression.
- The "" glyph can be typed in Squeak by
keying the underbar character (Shift-hyphen).
- An assignment expression answers the result of evaluating the
right-hand-side expression.
- Assignments can be cascaded as indicated above, resulting in the
assignment of the same right-hand-side result to each variable.
Messages
Unary Messages
theta sin
quantity sqrt
nameString size
1.5 tan rounded asString "answer the result of sending #asString
to the result of sending #rounded to the result of sending #tan to
1.5.
- Unary messages are messages without arguments.
- Unary messages are the most "tightly parsed" messages, and are
parsed left to right
Binary Messages
3 + 4 " ==> 7 "
3 + 4 * 5 " ==> 35 (not 23!) "
3 + 4 factorial " ==> 27 (not 1540!) "
total - 1
total <= max
- Binary messages have a receiver, the left hand side, and a single
argument, the right hand side. The first expression above sends 3
the message comprising the selector #+ with the argument 4.
- Binary messages are parsed left to right always, and without
regard to precedence of numeric operators unless corrected with
parentheses.
- Unary messages are parsed more tightly than binary messages
Keyword Messages
12 between: 8 and: 15 " ==> true "
#($t $e $s $t) at: 3 " ==> $s "
array at: index put: value "==> answers value, after storing
value in array at index"
array at: index factorial put: value "same, but this time stores
at index factorial"
1 to: 3 do: aBlock "This sends #to:do: (with two parameters) to integer 1"
(1 to: 3) do: aBlock "This sends #do: (with one parameter) to the
Interval given by evaluating '1 to: 3'"
- Keyword messages have 1 or more arguments
- Keyword messages are the least "tightly parsed messages." Binary
and unary messages are resolved first unless corrected with
parentheses.
Cascade Expressions
object
unaryMessage;
+ 23;
at: 23 put: value
- Each selector and description in the cascade is sent to object in
sequence. Intermediate answers are ignored, but side-effects on
object will be retained. The answer is the result of sending the
last message to object after sending all the preceding ones.
Expression Blocks
[ expression (.
expression)* (.) ] "block without
arguments"
[ (:
identifier)+ | expression (. expression)* (.) ]
"block with arguments"
[ 1. 2. 3 ] "a block that, when executed, will
answer the value 3"
[ object doWithSideEffects. test] "a block that,
when executed, will send #doSideEffects to object, and answer the
contents of test"
[ :each | each doSomething ] "a block that, when
executed with a parameter, will answer the result of sending
#doSomething to the parameter.
- A block represents a deferred sequence of actions.
- The value of a block expression is an object that can execute the
enclosed expressions at a later time when requested to do so.
- The selector #value, sent to a block, answers the result of
executing the parameterless block.
- The selector #value:, with an expression, answers the result of
executing the parameterless block with the answer of the expression
passed by value to the parameter.
- Ordinarily, expressions in a block are separated with a period.
A final period, if added, will be ignored.]
evaluating for BlockContext
Message |
Description |
Notes |
value |
Evaluate the block represented by the receiver and answer the result. | |
value: arg |
Evaluate the block represented by the receiver, passing it the value of the argument, arg. | 1 |
valueWithArguments: anArray |
Evaluate the block represented by the receiver. The argument
is an Array whose elements are the arguments for the block. Signal an error if the
length of the Array is not the same as the the number of arguments that
the block was expecting. | |
Note:
- Squeak also recognizes #value:value:, #value:value:value and #value:value:value:value. If you have a block with more than four parameters, you must use #valueWithArguments.
Control Structures
Alternative Control Structures (Receiver is Boolean)
Message |
Description |
Notes |
ifTrue: alternativeBlock |
Answer nil if the receiver is false. Signal an Error if the
receiver is nonBoolean. Otherwise, answer the result of evaluating alternativeBlock | 1,2 |
ifFalse: alternativeBlock |
Answer nil if the receiver is true. Signal an Error if the receiver is nonBoolean. Otherwise answer the result of evaluating
the argument, alternativeBlock. | 1,2 |
ifTrue: trueAlternativeBlock ifFalse: falseAlternativeBlock |
Answer the value of trueAlternativeBlock if the receiver is true.
Answer the value of falseAlternativeBlock if the receiver is false.
Otherwise, signal an Error. | 1,2 |
ifFalse: falseAlternativeBlock ifTrue: trueAlternativeBlock |
Same as ifTrue:ifFalse:. | 1,2 |
- These are not really control structures in principle, since they
can be understood as keyword messages that are sent to boolean
objects. (See the definitions of these methods in Classes True and
False, respectively).
- On the other hand, these expressions are in practice compiled in-line to bytecodes.
Alternative Control Structures (Receiver is any Object)
Message |
Description |
Notes |
ifNil: nilBlock |
Answer the result of evaluating nilblock if the receiver is nil. Otherwise answer the receiver. | Note |
ifNotNil: ifNotNilBlock |
Answer the result of evaluating ifNotNilBlock if the receiver is not nil. Otherwise answer nil. | Note |
ifNil: nilBlock ifNotNil: ifNotNilBlock |
Answer the result of evaluating nilBlock if the receiver is nil. Otherwise answer the result of evaluating ifNotNilBlock. | Note |
ifNotNil: ifNotNilBlock ifNil: nilBlock |
Same as #ifNil:ifNotNil: | Note |
Iterative Control Structures (receiver is BlockContext)
Message |
Description |
Notes |
whileTrue |
Evaluate the receiver. Continue to evaluate the receiver for so long as the result is true. | 1 |
whileTrue: aBlock |
Evaluate the receiver. If true, evaluate aBlock and repeat. | 1 |
whileFalse |
Evaluate the receiver. Continue to evaluate the receiver for so long as the result is false. | 1 |
whileFalse: aBlock |
Evaluate the receiver. If false, evaluate aBlock and repeat. | 1 |
- As with the alternative "control structures," these structures
can be understood as "traditional" methods on BlockContext objects, but in
practice are directly compiled in-line directly to bytecodes.
Enumeration Control Structures (Receiver is Integer)
Message |
Description |
Notes |
timesRepeat: aBlock |
Evaluate the argument, aBlock, the number of times represented by the
receiver. | |
to: stop do: aBlock |
Evaluate aBlock for each element of the interval (self to: stop by: 1). | 1 |
to: stop by: step do: aBlock |
Evaluate aBlock for each element of the interval (self to: stop by:
step). | 1 |
- #to:do and #to:do:by can be understood as "traditional" methods, but in
practice are compiled in-line directly to bytecodes.
Enumeration Control Structures (Receiver is Collection)
Message |
Description |
Notes |
do: aBlock |
For each element, each, of the collection, evaluate aBlock with each as its argument. | 1 |
- Squeak collections provide a very substantial, rich set of enumeration operators.
See the discussion of Collections below.
Case Structures (Receiver is any Object)
Message |
Description |
Notes |
caseOf: aBlockAssociationCollection |
Answer the evaluated value of the first association in aBlockAssociationCollection
whose evaluated key equals the receiver. If no match is found, signal an Error. | 1,2 |
caseOf: aBlockAssociationCollection otherwise: aBlock |
Answer the evaluated value of the first association in aBlockAssociationCollection
whose evaluated key equals the receiver. If no match is found, answer the result
of evaluating aBlock. | 1,2 |
- aBlockAssociationCollection is a collection of Associations (key/value pairs).
- Squeak attempts to compile #caseOf: in-line when possible.
Expression "Brace" Arrays
{ expression (.
expression)* (.) }
{ 1. 2. 3. 4. 5 } "An array of size 5 comprising
five Integers (1 to 5)"
{ $a #'brace' array } "An array of size 3
comprising a Character ($a) a Symbol (#brace), and the present
value of variable array."
{ 1 + 2 } "An array of size 1 comprising the single
integer 3."
- Brace arrays are bona-fide Smalltalk expressions that are
computed at runtime.
- The elements of a brace array are the answers of its component expressions.
- It is a sometimes convenient and more general alternative to the
arguably clunkier expression "Array with: expr1 with: expr2 with:
expr3"
- Indexing is 1-based.
Class Definition
Scalar Class Definition
SuperClass subclass: #NameOfClass
instanceVariableNames: 'instVarName1 instVarName2'
classVariableNames: 'ClassVarName1 ClassVarName2'
poolDictionaries: ''
category: 'Major-Minor'
Variable Class Definition
SuperClass variableSubclass: #NameOfClass
instanceVariableNames: 'instVarName1 instVarName2'
classVariableNames: 'ClassVarName1 ClassVarName2'
poolDictionaries: ''
category: 'Major-Minor'
SuperClass variableByteSubclass: #NameOfClass
instanceVariableNames: 'instVarName1 instVarName2'
classVariableNames: 'ClassVarName1 ClassVarName2'
poolDictionaries: ''
category: 'Major-Minor'
SuperClass variableWordSubclass: #NameOfClass
instanceVariableNames: 'instVarName1 instVarName2'
classVariableNames: 'ClassVarName1 ClassVarName2'
poolDictionaries: ''
category: 'Major-Minor'
Method Definition
lineCount
"Answer the number of lines represented by the receiver, where
every cr adds one line."
| cr count |
cr Character cr.
count 1 min: self size.
1 to: self size do:
[:i | (self at: i) == cr ifTrue: [count count + 1]].
^ count
Fundamental Classes and Methods
Class Object (Operations on all objects)
Instance Creation (Class Side)
Message |
Description |
Notes |
new |
Answer a new instance of the receiver (which is a class)
with no indexable variables. If the class is indexable, return an
instance with 0 indexable instance variables. |
note |
new: anInteger |
Answer an instance of the receiver (which is a class) with the
number of indexable variables specified by the argument,
anInteger. Signal an error if the class is not indexable or if the
argument is not a positive Integer. |
note |
Comparing Objects
Message |
Description |
Notes |
== anObject |
Answer whether the receiver and the argument are the same
object. Do not redefine the message == in
any other class. |
1 |
~~ anObject |
Answer whether the receiver and the argument are not the
same object. |
1 |
= anObject |
Answer whether the receiver and the argument represent the same
object. |
2 |
~= anObject |
Answer whether the receiver and the argument do not represent the
same object. |
2 |
hash |
Answer a SmallInteger whose value is related to the
receiver's identity. |
2 |
Notes:
- Two objects are identical when they have the same object pointer.
- Since various support classes (particularly Collections) rely on the property that
equal objects have equal hashes, you should override #hash whenever you override #=.
Testing Objects
Message |
Description |
Notes |
isNil |
Answer whether the receiver is nil. | Note |
notNil |
Answer whether the receiver is not nil. | Note |
Copying Objects
Message |
Description |
Notes |
copy |
Answer another instance just like the receiver.
Subclasses typically
override this method; they typically do not override shallowCopy. |
note |
shallowCopy |
Answer a copy of the receiver which shares the receiver's
instance variables. |
note |
deepCopy |
Answer a copy of the receiver with its own copy of each instance
variable. |
note |
veryDeepCopy |
Do a complete tree copy using a dictionary. An object in
the tree twice is only copied once. Both pointers point to one new
copy.
|
note |
message handling for Object
Message |
Description |
Notes |
perform: aSymbol |
Send the unary selector, aSymbol, to the receiver.
Signal an error if the number of arguments expected by the selector is not zero. | |
perform: aSymbol with: anObject |
Send the selector, aSymbol, to the receiver with anObject as its argument.
Fail if the number of arguments expected by the selector is not one. | 1 |
perform: selector withArguments: argArray |
Send the selector, aSymbol, to the receiver with arguments in argArray.
Fail if the number of arguments expected by the selector
does not match the size of argArray. | |
- Squeak objects also recognize #perform:with:with: and #perform:with:with:with
Indexing Objects
Message |
Description |
Notes |
at: index |
Answer the value of an
indexable element in the receiver. Signal an Error if the
argument index is not an
Integer or is out of bounds. |
note |
at: index put: anObject |
Store the argument value in
the indexable element of the receiver indicated by index.
Signal an Error if the
index is not an Integer or is out of bounds. Or fail if the
value is not of
the right type for this kind of collection. Answer the value that was
stored. |
note |
at: index modify: aBlock |
Replace the element of the collection with itself
transformed by the block. |
note |
size |
Answer the number of indexable variables in the receiver.
This value is the same as the largest legal subscript.
If the reciever does not have instance variables, then signal
an Error. |
note |
Displaying and Storing Objects
Message |
Description |
Notes |
printString |
Answer a String whose characters describe the receiver. |
note |
printOn: aStream |
Append to the argument, aStream, a String whose
characters describe the receiver. |
note |
storeString |
Answer a String from which the receiver can be reconstructed. |
note |
storeOn: aStream |
Append to the argument, aStream, a String from which the
receiver can be reconstructed |
note |
Functionality of an Object
Message |
Description |
Notes |
class |
Answer the object that is the receiver's class. |
note |
isKindOf: aClass |
Answer whether the argument, aClass, is a superclass or
class of the receiver. |
note |
isMemberOf: aClass |
Answer whether the argument, aClass, is a direct instance
of the argument, aClass. (Same as 'rcvr class == aClass') |
note |
respondsTo: aSymbol |
Answer whether the method dictionary of the receiver's
class or one of its superclasses contains the argument, aSymbol, as a
message selector. |
note |
Miscellaneous Messages
Message |
Description |
Notes |
yourself |
Answers self. |
1 |
asString |
Answers the receiver's printString. |
1 |
doesNotUnderstand: aSymbol |
Report to the user that the receiver does not understand
the argument, aSymbol, as a message. |
note |
error: aString |
Signal an Error exception. |
note |
Class Boolean
This abstract class represents logical values, providing boolean operations and conditional control structures.
It has two subclasses, True and False, each of which have singleton elements represented by the Squeak keywords true and false, respectively.
Evaluating and Non-Evaluating Logical Operations for Boolean
Message |
Description |
Notes |
& aBoolean |
Evaluating conjunction. Evaluate the argument. Then answer true if
both the receiver and the argument are true. | Note |
eqv: aBoolean |
Answer true if the receiver is equivalent to aBoolean. | Note |
not |
Negation. Answer true if the receiver is false, answer false if the
receiver is true. | Note |
xor: aBoolean |
Exclusive OR. Answer true if the receiver is not equivalent to aBoolean. | Note |
| aBoolean |
Evaluating disjunction (OR). Evaluate the argument. Then answer true
if either the receiver or the argument is true. | Note |
and: alternativeBlock |
Nonevaluating conjunction. If the receiver is true, answer the value of
the argument, alternativeBlock; otherwise answer false without
evaluating the argument. | Note |
or: alternativeBlock |
Nonevaluating disjunction. If the receiver is false, answer the value of
the argument, alternativeBlock; otherwise answer true without
evaluating the argument. | Note |
Magnitude
This abstract class embraces, among other classes, Numbers,
Characters, Date and Time. It addresses classes whose instances can
be linearly ordered.
Message |
Description |
Notes |
< aMagnitude |
Answer whether the receiver is strictly less than the
argument. |
note |
> aMagnitude |
Answer whether the receiver is strictly greater than the
argument. |
note |
<= aMagnitude |
Answer whether the receiver is less than or equal to the
argument. |
note |
>= aMagnitude |
Answer whether the receiver is greater than or equal to
the argument. |
note |
between: min and: max |
Answer whether the receiver is greater than or equal to
the argument, min, and less than or equal to the argument, max. |
note |
min: aMagnitude |
Answer the receiver or the argument, whichever is the
lesser magnitude. |
note |
max: aMagnitude |
Answer the receiver or the argument, whichever is the
greater magnitude. |
note |
min: firstMagnitude max: secondMagnitude |
Take the receiver or the argument, firstMagnitude,
whichever is the lesser magnitude, and answer that or the argument,
secondMagnitude, whichever is the greater magnitutde. |
note |
Character
Class Character
Instances of class character store the associated 8-bit extended ASCII code.
Character has the unique element property, so that all equal ("=") instances of a
character are identical ("=="). That is, a asciValue == b asciiValue if,
and only if, a == b).
accessing for Character
Message |
Description |
Notes |
asciiValue |
Answer the value of the receiver that represents its ascii encoding. | Note |
digitValue |
Answer 0-9 if the receiver is $0-$9, 10-35 if it is $A-$Z, and < 0
otherwise. This is used to parse literal numbers of radix 2-36. | Note |
testing for Character
Message |
Description |
Notes |
isAlphaNumeric |
Answer whether the receiver is a letter or a digit. | Note |
isDigit |
Answer whether the receiver is a digit. | Note |
isLetter |
Answer whether the receiver is a letter. | Note |
isLowercase |
Answer whether the receiver is a lowercase letter.
(The old implementation answered whether the receiver is not an uppercase letter.) | Note |
isSeparator |
Answer whether the receiver is one of the separator characters--space,
cr, tab, line feed, or form feed. | Note |
isSpecial |
Answer whether the receiver is one of the special characters | Note |
isUppercase |
Answer whether the receiver is an uppercase letter.
(The old implementation answered whether the receiver is not a lowercase letter.) | Note |
isVowel |
Answer whether the receiver is one of the vowels, AEIOU, in upper or
lower case. | Note |
tokenish |
Answer whether the receiver is a valid token-character--letter, digit, or
colon. | Note |
converting for Character
Message |
Description |
Notes |
asLowercase |
If the receiver is uppercase, answer its matching lowercase Character. | Note |
asUppercase |
If the receiver is lowercase, answer its matching uppercase Character. | Note |
Numeric Classes and Methods
Number
This abstract class embraces Integers, Floats and Fractions. Number
is a subclass of Magnitude.
Arithmetic for All Numeric Classes
Message |
Description |
Notes |
+ aNumber |
Answer the sum of the receiver and the argument. |
note |
- aNumber |
Answer the difference of the receiver and the argument. |
note |
* aNumber |
Answer the product of the receiver and the argument. |
note |
/ aNumber |
Answer the result of dividing the receiver and the
argument, retaining as much precision as possible. If the answer is
not exact, the result will be Fraction or Float, as appropriate.
Signal ZeroDivide if the argument is Zero. |
note |
// aNumber |
Answer the result of dividing the receiver and the
argument, truncating toward negative infinity. Signal ZeroDivide if
the argument is Zero. |
note |
\\ aNumber |
Answer the remainder of dividing the receiver and the
argument, truncating toward negative infinity. This is the modulus
operator. Signal ZeroDivide if the argument is Zero. |
note |
quo: aNumber |
Answer the result of dividing the receiver and the
argument, truncating toward zero. Signal ZeroDivide if the argument
is Zero. |
note |
rem: aNumber |
Answer the remainder of dividing the receiver and the
argument, truncating toward zero. Signal ZeroDivide if the argument
is Zero. |
note |
abs |
Answer the absolute value of the receiver. |
note |
negated |
Answer the negation of the receiver. |
note |
reciprocal |
Answer 1 divided by the receiver. Signal ZeroDivide if
the receiver is zero. |
note |
Mathematical Functions for All Numbers
Message |
Description |
Notes |
exp |
Answer a floating point number that is the exponential of
the reciever |
note |
ln |
Answer the natural log of the receiver. |
note |
log: aNumber |
Answer the logarithm base aNumber of the reciever. |
note |
floorLog: aNumber |
Take the logarithm base aNumber of the reciever, and
answer the integer nearest that value towards negative infinity. |
note |
raisedTo: aNumber |
Answer the receiver raised to the power of the argument,
aNumber. |
note |
raisedToInteger: anInteger |
Answer the receiver raised to the power of the argument,
anInteger. Signal an Error if anInteger is not an integer. |
note |
sqrt |
Answer a floating point number that is the positive
square root of the receiver. |
note |
squared |
Answer the receiver multiplied by itself. |
note |
Testing Operations for All Numbers
Message |
Description |
Notes |
even |
Answer whether the receiver is even. |
note |
odd |
Answer whether the receiver is odd. |
note |
negative |
Answer whether the receiver is less than zero. |
note |
positive |
Answer whether the receiver is greater than or equal to zero. |
note |
strictlyPositive |
Answer whether the receiver is greater than zero. |
note |
sign |
Answer 1 if the receiver is strictly positive, zero if
the receiver is zero, and -1 if the receiver is strictly
negative. |
note |
isZero |
Answer whether the receiver is zero. | note |
Truncation and Rounding for All Numbers
Message |
Description |
Notes |
ceiling |
Answer the Integer nearest the receiver toward positive infinity. | note |
floor |
Answer the Integer nearest the receiver toward negative infinity. | note |
truncated |
Answer an integer nearest the receiver toward zero. | note |
truncateTo: aNumber |
Answer the next multiple of aNumber toward zero that is nearest the receiver. | note |
rounded |
Answer the integer nearest the receiver. | note |
roundTo: quantum |
Answer the nearest number that is a multiple of quantum. | note |
roundUpTo: quantum |
Answer the next multiple of aNumber toward infinity that is nearest the
receiver. | note |
Trigonometric Operations for All Numbers
Message |
Description |
Notes |
sin |
Answer the sine of the receiver taken as an angle in radians. | note |
cos |
Answer the cosine of the receiver taken as an angle in radians. | note |
tan |
Answer the tangent of the receiver taken as an angle in radians. | note |
degreeSin |
Answer the sin of the receiver taken as an angle in degrees. | note |
degreeCos |
Answer the cosine of the receiver taken as an angle in degrees. | note |
arcSin |
Answer an angle in radians whose sine is the receiver. | note |
arcCos |
Answer an angle in radians whose cosine is the receiver. | note |
arcTan |
Answer an angle in radians whose tangent is the receiver. | note |
arcTan: denominator |
Answer the angle in radians whose tan is the receiver divided by denominator. | note |
degreesToRadians |
Answer the receiver in radians. Assumes the receiver is in degrees. | note |
radiansToDegrees |
Answer the receiver in degrees. Assumes the receiver is in radians. | note |
Integer
Arithmetic Operations for All Integers
Message |
Description |
Notes |
isPowerOfTwo |
Answer whether the receiver is a power of two. | Notes |
factorial |
Answer the factorial of the receiver. | Notes |
gcd: anInteger |
Answer the greatest common denominator of the receiver and the argument. | Notes |
lcm: anInteger |
Answer the least common multiple of the receiver and the argument. | Notes |
take: anInteger |
Answer the number of combinations of the receiver, taken the argument, anInteger, at a time. | Notes |
Bit Manipulation Operations for All Integers
Message |
Description |
Notes |
bitShift: anInteger |
Answer an Integer whose value (in twos-complement representation) is
the receiver's value (in twos-complement representation) shifted left by
the number of bits indicated by the argument, anInteger. Negative arguments shift
right. Zeros are shifted in from the right in left shifts. | Notes |
<< anInteger |
Answer "theReceiver bitShift: anInteger" | Notes |
>&tg; anInteger |
Answer "theReceiver bitShift: 0 - anInteger | Notes |
bitAnd: anInteger |
Answer an Integer whose bits are the logical AND of the receiver's bits
and those of the argument, anInteger. | Notes |
bitOr: anInteger |
Answer an Integer whose bits are the logical OR of the receiver's bits
and those of the argument, anInteger. | Notes |
bitXor: anInteger |
Answer an Integer whose bits are the logical XOR of the receiver's bits
and those of the argument, anInteger. | Notes |
bitInvert |
Answer an Integer whose bits are the logical negation of the receiver's bits.
Numbers are interpreted as having 2's-complement representation. | Notes |
bitInvert32 |
Answer the 32-bit complement of the receiver. | Notes |
lowBit |
Answer zero if the receiver is zero. Otherwise, answer the index of the rightmost bit that has been set in the receiver, counting the rightmost bit as 1. | Notes |
bitClear: aMask |
Answer an Integer equal to the receiver, but with all bits cleared that are set in the argument, aMask. | Notes |
allMask: mask |
Treat the argument as a bit mask. Answer whether all of the bits that
are 1 in the argument are 1 in the receiver. | Notes |
anyMask: mask |
Treat the argument as a bit mask. Answer whether any of the bits that
are 1 in the argument are 1 in the receiver. | Notes |
noMask: mask |
Treat the argument as a bit mask. Answer whether none of the bits that
are 1 in the argument are 1 in the receiver. | Notes |
Collection Classes and Methods
The Collection Hierarchy
Class |
Description |
Collection | Abstract Class for Collections |
Bag | Unordered, unindexed collection of objects |
Set | Unordered, unindexed collection of unique objects |
Dictionary | Set of associations (values are indexable by keys) |
IdentityDictionary | Dictionary, but comparisons are done using == |
IdentitySet | Set, but comparisons are done using == |
SequenceableCollection | Ordered collection, indexed by integers |
OrderedCollection | Ordered according to manner elements are added and removed |
SortedCollection | Ordered according to value of a "sortBlock" |
LinkedList | Homogeneous SequenceableCollection of Links |
Interval | Homogeneous sequence of arithmetic progression of Integers |
ArrayedCollection | Ordered collection, indexed by fixed range of Integers |
Array | ArrayedCollection of arbitrary Objects |
Array2D | Homogeneous ArrayedCollection of Arrays |
ByteArray | Homogeneous ArrayedCollection of Bytes (Integers -128..255) |
FloatArray | Homogeneous ArrayedCollection of Floating point numbers |
IntegerArray | Homogeneous ArrayedCollection of Signed 32-bit Integers |
PointArray | Homogeneous ArrayedCollection of Points (with 32-bit values) |
RunArray | Homogeneous ArrayedCollection of Integers (sparse RLE representation) |
ShortIntegerArray | Homogeneous ArrayedCollection of Signed 16-bit Integers |
ShortPointArray | Homogeneous ArrayedCollection of Points (with 16-bit values) |
ShortRunArray | Homogeneous ArrayedCollection of Signed 16-bit Ints (sparse RLE rep) |
String | Homogeneous ArrayedCollection of Characters |
Symbol | Homogeneous ArrayedCollection of Characters (with unique instance property) |
Text | Homogeneous ArrayedCollection of Characters with associated text attributes |
WordArray | Homogeneous ArrayedCollection of Unsigned 32-bit Integers |
Heap | Like SortedCollection, but stores information as a heap. (see Heapsort) |
MappedCollection | Means for accessing an indexable Collection, using a mapping from a
collection of "external" keys to the accessed collection's "indexing" keys.
The MappedCollection can then be used directly, indexing and changing the
accessed collection via the external keys. |
Collection
Creating Collections (Class Side)
Message |
Description |
Notes |
with: anObject |
Answer an instance of the receiver containing anObject | Note |
with: firstObject with: secondObject |
Answer an instance of the receiver containing all the arguments as elements. (Squeak recognizes instantiators of this type up to six "with:" clauses). | Note |
withAll: aCollection |
Answer an instance of the receiver containing all the elements from aCollection. | Note |
Testing, Adding and Removing Collection Elements
Message |
Description |
Notes |
anyOne |
Answer a specimen element of the receiver (any one at all). Signal an error if the receiver is empty. | Note |
isEmpty |
Answer whether the receiver contains any elements. | Note |
occurrencesOf: anObject |
Answer how many of the receiver's elements are equal to anObject. | Note |
anySatisfy: aBlock | Evaluate aBlock with the elements of the receiver.
If aBlock returns true for any element return true.
Otherwise return false | Note |
includes: anObject |
Answer whether anObject is one of the receiver's elements. | Note |
includesAllOf: aCollection |
Answer whether all the elements of aCollection are in the receiver. | Note |
includesAnyOf: aCollection |
Answer whether any element of aCollection is one of the receiver's elements. | Note |
add: newObject |
Include newObject as one of the receiver's elements. Answer newObject.
ArrayedCollections cannot respond to this message. | Note |
addAll: newObject |
Include all the elements of aCollection as the receiver's elements. Answer
aCollection. | Note |
remove: oldObject |
Remove oldObject as one of the receiver's elements. Answer oldObject
unless no element is equal to oldObject, in which case, signal an Error. | Note |
remove: oldObject ifAbsent: anExceptionBlock |
Remove oldObject as one of the receiver's elements. If several of the
elements are equal to oldObject, only one is removed. If no element is
equal to oldObject, answer the result of evaluating anExceptionBlock.
Otherwise, answer the argument, oldObject. SequenceableCollections
cannot respond to this message. | Note |
removeAll: aCollection |
Remove each element of aCollection from the receiver. If successful for
each, answer aCollection. Otherwise signal an Error. | Note |
removeAllFoundIn: aCollection |
Remove each element of aCollection which is present in the receiver from the receiver | Note |
removeAllSuchThat: aBlock |
Apply the condition to each element and remove it if the condition is true. | Note |
Enumerating Collections
Message |
Description |
Notes |
do: aBlock |
Evaluate aBlock with each of the receiver's elements as the argument. | Note |
do: aBlock separatedBy: separatorBlock |
Evaluate the elementBlock for all elements in the receiver,
and if there is more than one element, evaluate the separatorBlock between each pair of elements in the receiver. | Note |
select: aBlock |
Evaluate aBlock with each of the receiver's elements as the argument.
Collect into a new collection like the receiver, only those elements for
which aBlock evaluates to true. Answer the new collection. | Note |
reject: aBlock |
Evaluate aBlock with each of the receiver's elements as the argument.
Collect into a new collection like the receiver only those elements for
which aBlock evaluates to false. Answer the new collection. | Note |
collect: aBlock |
Evaluate aBlock with each of the receiver's elements as the argument.
Collect the resulting values into a collection like the receiver. Answer
the new collection. | Note |
detect: aBlock |
Evaluate aBlock with each of the receiver's elements as the argument.
Answer the first element for which aBlock evaluates to true. Signal an Error if none are found. | Note |
detect: aBlock ifNone: exceptionBlock |
Evaluate aBlock with each of the receiver's elements as the argument.
Answer the first element for which aBlock evaluates to true. If none
evaluate to true, then evaluate the argument, exceptionBlock. | Note |
inject: initialValue into: binaryBlock |
Accumulate a running value associated with evaluating the argument,
binaryBlock, with the current value of the argument, thisValue, and the
receiver as block arguments. For example, to compute the sum of the elements
of a numeric collection, aCollection inject: 0 into: [:subTotal :next | subTotal +
next]. | Note |
collect: aBlock thenSelect: aBlock |
Evaluate aBlock with each of the receiver's elements as the argument.
Collect the resulting values into a collection like the receiver. Answer
the new collection. | Note |
select: aBlock thenCollect: aBlock |
Evaluate aBlock with each of the receiver's elements as the argument.
Collect into a new collection like the receiver, only those elements for
which aBlock evaluates to true. Answer the new collection. | Note |
count: aBlock |
Evaluate aBlock with each of the receiver's elements as the argument. Return the number that answered true. | Note |
Bag
Message |
Description |
Notes |
add: newObject withOccurrences: anInteger |
Add the element newObject to the receiver. Do so as though the element
were added anInteger number of times. Answer newObject. | Note |
Dictionary and IdentityDictionary
Dictionaries are homogenous Sets of key and value pairs, called Associations, where key and value can be any object.
Instances of Association are created by sending the binary message "key -> value" (The selector, ->, is defined in Object).
Dictionaries have the property that each key occurs at most once. IdentityDictionaries have the same property, but
determine uniqueness of keys using == instead of =. In ordinary use, they are indexed using the unique key to obtain
the corresponding value.
Message |
Description |
Notes |
at: key |
Answer the value associated with key. Signal an Error if no value is associated with key. | Note |
at: key ifAbsent: aBlock |
Answer the value associated with key. If no value is associated with key, answer the value of aBlock. | Note |
associationAt: key |
Answer the association associated with the argument, key. Signal an Error if no association has the argument, key, as its key. | Note |
associationAt: key ifAbsent: aBlock |
Answer the association associated with the argument, key. If no association has the argument, key, as its key, answer the value of aBlock. | Note |
keyAtValue: value |
Answer the key for the first association having argument, value. If
there are none, signal an Error. | Note |
keyAtValue: value ifAbsent: exceptionBlock |
Answer the key for the first associaiton having argument, value. If
there are none, answer the result of evaluating exceptionBlock. | Note |
keys |
Answer a Set containing the receiver's keys. | Note |
values |
Answer an Array containing the receiver's values. | Note |
includes: value |
Answer whether the receiver has a value equal to the argument, value. | Note |
includesKey: key>
| Answer whether the receiver has a key equal to the argument, key. | Note |
do: aBlock |
Evaluate aBlock for each of the receiver's values | Note |
keysDo: aBlock |
Evaluate aBlock for each of the receiver's keys. | Note |
valuesDo: aBlock |
same as #do: | Note |
keysAndValuesDo: binaryBlock |
Evaluate binaryBlock with each of the receiver's key/value pairs | Note |
associationsDo: aBlock |
Evaluate aBlock for each of the receiver's elements (key/value
associations). | Note |
Sequenceable Collection
Methods for Accessing SequenceableCollections
Message |
Description |
Notes |
atAll: indexCollection |
Answer a collection containing the elements of the receiver specified by the integer elements of the argument, indexCollection. | Note |
atAll: aCollection put: anObject |
Put anObject at every index specified by the integer elements of
the argument, aCollection. | Note |
atAllPut: anObject |
Put anObject at every one of the receiver's indices. | Note |
first |
Answer the first element of the receiver. (Squeak also recognizes second, third, fourth, fifth and sixth). Signal an error if there aren't sufficient elements in the receiver. | Note |
middle |
Answer the median element of the receiver. Signal an error if the receiver is empty. | Note |
last |
Answer the last element of the reciever. Signal an error if the receiver is empty. | Note |
allButFirst |
Answer a collection equal to the reciever, but without the first element. Signal an error if the receiver is empty. | Note |
allButLast |
Answer a collection equal to the reciever, but without the last element. Signal an error if the receiver is empty. | Note |
indexOf: anElement |
Answer the index of anElement within the receiver. If the receiver does
not contain anElement, answer 0. | Note |
indexOf: anElement ifAbsent: exceptionBlock |
Answer the index of anElement within the receiver. If the receiver does
not contain anElement, answer the result of evaluating the argument,
exceptionBlock. | Note |
indexOfSubCollection: aSubCollection startingAt: anIndex |
Answer the index of the receiver's first element, such that that element
equals the first element of aSubCollection, and the next elements equal
the rest of the elements of aSubCollection. Begin the search at element
anIndex of the receiver. If no such match is found, answer 0. | Note |
indexOfSubCollection: aSubCollection startingAt: anIndex ifAbsent: exceptionBlock |
Answer the index of the receiver's first element, such that that element
equals the first element of sub, and the next elements equal
the rest of the elements of sub. Begin the search at element
start of the receiver. If no such match is found, answer the result of
evaluating argument, exceptionBlock. | Note |
replaceFrom: start to: stop with: replacementCollection |
This destructively replaces elements from start to stop in the receiver.
Answer the receiver itself. Use copyReplaceFrom:to:with: for
insertion/deletion which may alter the size of the result. | Note |
replaceFrom: start to: stop: with: replacementCollection startingAt: repStart |
This destructively replaces elements from start to stop in the receiver
starting at index, repStart, in the sequenceable collection,
replacementCollection. Answer the receiver. No range checks are
performed. | Note |
Copying Sequenceable Collections
Message |
Description |
Notes |
, otherCollection |
Answer a new collection comprising the receiver concatenated with the argument, otherCollection. | Note |
copyFrom: start to: stop |
Answer a copy of a subset of the receiver, starting from element at
index start until element at index stop. | Note |
copyReplaceAll: oldSubCollection with: newSubCollection |
Answer a copy of the receiver in which all occurrences of
oldSubstring have been replaced by newSubstring. | Note |
copyReplaceFrom: start to: stop with: replacementCollection |
Answer a copy of the receiver satisfying the following conditions: If
stop is less than start, then this is an insertion; stop should be exactly
start-1, start = 1 means insert before the first character, start = size+1
means append after last character. Otherwise, this is a replacement; start
and stop have to be within the receiver's bounds. | Note |
copyWith: newElement |
Answer a copy of the receiver that is 1 bigger than the receiver and has
newElement at the last element. | Note |
copyWithout: oldElement |
Answer a copy of the receiver in which all occurrences of oldElement have been left out. | Note |
copyWithoutAll: aList |
Answer a copy of the receiver in which all occurrences of all elements in aList have been removed. | Note |
forceTo: length paddingWith: anElement |
Force the length of the collection to length, padding if necissary
with elem. Note that this makes a copy. | Note |
reversed |
Answer a copy of the receiver in which the sequencing of all the elements has been reversed. | Note |
shuffled |
Answer a copy of the receiver in which the elements have been permuted randomly. | Note |
sortBy: aBlock |
Create a copy that is sorted. Sort criteria is the block that accepts two arguments. When the block is true, the first arg goes first ([:a :b | a > b] sorts in descending order). | Note |
Enumerating Sequenceable Collections
Message |
Description |
Notes |
findFirst: aBlock |
Return the index of the receiver's first element for which aBlock evaluates as true. | Note |
findLast: aBlock |
Return the index of the receiver's last element for which aBlock evaluates as true. | Note |
keysAndValuesDo: aBinaryBlock |
Evaluate aBinaryBlock once with each valid index for the receiver in order, along with the corresponding value in the receiver for that index. | Note |
reverseDo: aBlock |
Evaluate aBlock with each of the receiver's elements as the argument,
starting with the last element and taking each in sequence up to the
first. For SequenceableCollections, this is the reverse of the enumeration
for #do:. | Note |
with: otherCollection do: binaryBlock |
Evaluate binaryBlock with corresponding elements from this collection and otherCollection. | Note |
reverseWith: aSequenceableCollection do: aBinaryBlock |
Evaluate aBinaryBlock with each of the receiver's elements, in reverse order,
along with the corresponding element, also in reverse order, from
aSequencableCollection. | Note |
Ordered Collections
Message |
Description |
Notes |
add: newObject before: oldObject |
Add the argument, newObject, as an element of the receiver. Put it in
the sequence just preceding oldObject. Answer newObject. | Note |
add: newObject after: oldObject |
Add the argument, newObject, as an element of the receiver. Put it in
the sequence just succeeding oldObject. Answer newObject. | Note |
add: newObject afterIndex: index |
Add the argument, newObject, as an element of the receiver. Put it in
the sequence just after index. Answer newObject. | Note |
addFirst: anElement |
Add newObject to the beginning of the receiver. Answer newObject. | Note |
addAllFirst: anOrderedCollection |
Add each element of anOrderedCollection at the beginning of the
receiver. Answer anOrderedCollection. | Note |
addLast: anElement |
Add newObject to the end of the receiver. Answer newObject. | Note |
addAllLast: anOrderedCollection |
Add each element of anOrderedCollection at the end of the receiver.
Answer anOrderedCollection. | Note |
removeAt: anIndex |
remove the element of the receiver at location anIndex. | Note |
removeFirst |
Remove the first element of the receiver and answer it. If the receiver is
empty, signal an Error. | Note |
removeLast |
Remove the last element of the receiver and answer it. If the receiver is
empty, signal an Error. | Note |
Strings
String is an extensive class, built over the ages in something of an ad hoc manner. We describe here only a small fraction of the methods provided.
Accessing Strings
Message |
Description |
Notes |
findAnySubStr: delimiters startingAt: start |
Answer the index of the character within the receiver, starting at start, that begins a substring matching one of the delimiters. delimiters is an Array of Strings (Characters are permitted also). If the receiver does not contain any of the delimiters, answer size + 1. | Note |
findBetweenSubStrs: delimiters |
Answer the collection of tokens that result from parsing the receiver. Tokens are separated by substrings, as listed in the Array delimiters. | Note |
findDelimiters: delimiters startingAt: start |
Answer the index of the character within the receiver, starting at start, that matches one of the delimiters. If the receiver does not contain any of the delimiters, answer size + 1. | Note |
findString: subString |
Answer the first index of subString within the receiver. If
the receiver does not contain subString, answer 0. | Note |
findString: subString startingAt: start |
Answer the index of subString within the receiver, starting at start. If
the receiver does not contain subString, answer 0. | Note |
findTokens: delimiters |
Answer the collection of tokens that result from parsing the receiver. Any character in the argument, delimiters, marks a border. Several delimiters in a row are considered as just one separation. | Note |
indexOf: aCharacter |
Answer the index of the first occurrence of aCharacter in the receiver. 0 Otherwise. | Note |
indexOf: aCharacter startingAt: start |
Answer the index of the first occurrence of aCharacter in the receiver, beginning at index start. 0 Otherwise. | Note |
indexOf: aCharacter startingAt: start ifAbsent: aBlock |
Answer the index of the first occurrence of aCharacter in the receiver, beginning at index start. If not present, answer the value of aBlock. | Note |
indexOfAnyOf: aCharacterSet |
returns the index of the first character in the given set. Returns 0 if none are found. (As with #indexOf:, there are corresponding messages #indexOfAnyOf:ifAbsent:, #indexOfAnyOf:startingAt: and #indexOfAnyOf:startingAt:ifAbsent:) | Note |
Comparing Strings
Message |
Description |
Notes |
<,<=,=,>,>= |
Answer whether the receiver sorts as indicated with the argument.
The collation order is simple ascii (and therefore case-sensitive). | Note |
sameAs: aString |
Answer whether the receiver sorts equal to aString. The
collation sequence is ascii with case differences ignored. | Note |
compare: aString |
Answer a comparison code telling how the receiver sorts relative to the argument, aString, as follows:
1 - receiver before aString; 2 - receiver equal to aString; and 3 - receiver after aString. The collation sequence is ascii with case differences ignored. | Note |
match: text |
Answer whether text matches the pattern in the receiver. Matching ignores upper/lower case differences. Where the receiver contains #, text may contain any character. Where the receiver contains *, text may contain any sequence of characters. | Note |
beginsWith: prefix |
Answer whether the receiver begins with the argument, prefix. | Note |
endsWith: prefix |
Answer whether the receiver ends with the argument, prefix. | Note |
Converting Strings
Message |
Description |
Notes |
asLowercase |
Answer a String made up from the receiver whose characters are all
lowercase. | Note |
asUppercase |
Answer a String made up from the receiver whose characters are all
uppercase. | Note |
capitalized |
Answer a copy of the receiver with the first letter capitalized | Note |
translateFrom: start to: stop with: table |
Argument, table, is a String representing a translation table. In situ, translate each character in the receiver from index argument, start, to argument, stop, with the corresponding character from argument, table. | Note |
Streaming Classes and Methods
The Stream Hierarchy
Class |
Description |
Stream | Abstract Class for Accessors |
PositionableStream | Accessors for Collections Indexable by an Integer |
ReadStream | Read-Only |
WriteStream | Write-Only |
ReadWriteStream | Read and/or Write |
FileStream | Accessors for collections whose elements are "paged in" |
StandardFileStream | Accessors for files accessed from a file system |
CrLfFileStream | Automatically handles system-specific line endings |
DummyStream | Like /dev/null |
Class Stream
Stream is an abstract class for an accessor to a sequence of objects, called the contents.
The stream is said to be "advanced" when the stream is configured to access a later element
of the contents.
accessing for Stream
Message |
Description |
Notes |
contents |
Answer the entire contents of the receiver. | Note |
next |
Answer the next object accessible by the receiver. | Note |
next: anInteger |
Answer the next anInteger number of objects accessible by the receiver. | Note |
next: anInteger put: anObject |
Make anObject be the next anInteger number of objects accessible by the
receiver. Answer anObject. | Note |
nextMatchAll: aColl |
Answer true if next N objects are the ones in aColl,
else false. Advance stream if true, leave as was if false. | Note |
nextMatchFor: anObject |
Answer whether the next object is equal to the argument,
anObject, advancing the stream. | Note |
nextPut: anObject |
Insert the argument, anObject, as the next object accessible by the
receiver. Answer anObject. | Note |
nextPutAll: aCollection |
Append the elements of aCollection to the sequence of objects accessible
by the receiver. Answer aCollection. | Note |
upToEnd |
Answer the remaining elements in the string | Note |
testing for Stream
Message |
Description |
Notes |
atEnd |
Answer whether the receiver can access any more objects. | Note |
enumerating for Stream
Message |
Description |
Notes |
do: aBlock |
Evaluate aBlock for each of the remaining objects accessible by receiver. | Note |
Class PositionableStream
PositionableStream is an abstract class for accessors to sequences of objects that can be externally
named by indices so that the point of access can be repositioned. Concrete classes ReadStream,
WriteStream and ReadWriteStream are typically used to instantiate a PositionableStream on Collections, depending
upon the access mode. StandardFileStream and CRLFFileStream are typically used for instantiating PositionableStreams for Files.
accessing for PositionableStream
Message |
Description |
Notes |
contentsOfEntireFile |
Answer a collection containing the remainder of the receiver. | Note |
last |
Return the final element of the receiver. | Note |
nextDelimited: terminator |
Answer the contents of the receiver, from the current position up to the next terminator character; provided, however, that doubled terminators will be included as a single element. | Note |
nextInto: buffer |
Given buffer, an indexable object of size n, fill buffer with the next n objects of the receiver. | Note |
nextLine |
Answer next line (may be empty), or nil if at end | Note |
originalContents |
Answer the receiver's actual contents collection. (#contents returns a copy) | Note |
peek |
Answer what would be returned if the message next were sent to the
receiver. If the receiver is at the end, answer nil. | Note |
peekFor: anObject |
Answer false and do not move over the next element if it is not equal to
the argument, anObject, or if the receiver is at the end. Answer true
and increment the position for accessing elements, if the next element is
equal to anObject. | Note |
upTo: anObject |
Answer a subcollection from the current access position to the
occurrence (if any, but not inclusive) of anObject in the receiver. If
anObject is not in the collection, answer the entire rest of the receiver. | Note |
upToAll: aCollection |
Answer a subcollection from the current access position to the occurrence (if any, but not inclusive) of aCollection. If aCollection is not in the stream, answer the entire rest of the stream. | Note |
testing for PositionableStream
Message |
Description |
Notes |
isEmpty |
Answer whether the receiver's contents has no elements. | Note |
positioning for PositionableStream
Message |
Description |
Notes |
match: subCollection |
Set the access position of the receiver to be past the next occurrence of the subCollection. Answer whether subCollection is found. No wildcards, and case does matter. | Note |
padTo: nBytes put: aCharacter |
Pad using the argument, aCharacter, to the next boundary of nBytes characters. | Note |
padToNextLongPut: char |
Make position be on long word boundary, writing the padding
character, char, if necessary. | Note |
position |
Answer the current position of accessing the sequence of objects. | Note |
position: anInteger |
Set the current position for accessing the objects to be anInteger, as long
as anInteger is within the bounds of the receiver's contents. If it is not,
create an error notification. | Note |
reset |
Set the receiver's position to the beginning of the sequence of objects. | Note |
resetContents |
Set the position and limits to 0. | Note |
setToEnd |
Set the position of the receiver to the end of the sequence of objects. | Note |
skip: anInteger |
Set the receiver's position to be the current position+anInteger. A
subclass might choose to be more helpful and select the minimum of the
receiver's size and position+anInteger, or the maximum of 1 and
position+anInteger for the repositioning. | Note |
skipTo: anObject |
Set the access position of the receiver to be past the next occurrence of
anObject. Answer whether anObject is found. | Note |
nonhomogeneous accessing for PositionableStream
Message |
Description |
Notes |
nextInt32 |
Read a 32-bit signed integer from the next 4 bytes | Note |
nextInt32Put: int32 |
Write a signed integer to the next 4 bytes | Note |
nextLittleEndianNumber: n put: value |
Answer the next n bytes as a positive Integer or LargePositiveInteger, where the bytes are ordered from least significant to most significant. | Note |
nextLittleEndianNumber: n |
Answer the next n bytes as a positive Integer or LargePositiveInteger, where the bytes are ordered from least significant to most significant. | Note |
nextNumber: n |
Answer the next n bytes as a positive Integer or LargePositiveInteger. | Note |
nextNumber: n put: v |
Append to the receiver the argument, v, which is a positive
SmallInteger or a LargePositiveInteger, as the next n bytes.
Possibly pad with leading zeros. | Note |
nextString |
Read a string from the receiver. The first byte is the length of the string, unless it is greater than 192, in which case the first four bytes encode the length. I expect to be in ascii mode when called (caller puts back to binary). | Note |
nextStringOld |
Read a string from the receiver. The first byte is the length of the
string, unless it is greater than 192, in which case the first *two* bytes
encode the length. Max size 16K. | Note |
nextStringPut: s |
Append the string, s, to the receiver. Only used by DataStream. Max size of 64*256*256*256. | Note |
nextWord |
Answer the next two bytes from the receiver as an Integer. | Note |
nextWordPut: aWord |
Append to the receiver an Integer as the next two bytes. | Note |
Class WriteStream
character writing for WriteStream
Message |
Description |
Notes |
cr |
Append a return character to the receiver. | Note |
crtab |
Append a return character, followed by a single tab character, to the
receiver. | Note |
crtab: anInteger |
Append a return character, followed by anInteger tab characters, to the
receiver. | Note |
space |
Append a space character to the receiver. | Note |
tab |
Append a tab character to the receiver. | Note |
Class ReadWriteStream
file status for ReadWriteStream
Message |
Description |
Notes |
close |
Presumably sets the status of the receiver to be closed. This message does
nothing at this level, but is included for FileStream compatibility. | Note |
closed |
If you have close (for FileStream compatibility), you must respond to closed. The result in nonsense here. TK 29 May 96 | Note |
ANSI-Compatible Exceptions
Evaluating Blocks With Exceptions
exceptions for BlockContext
Message |
Description |
Notes |
ensure: aBlock |
Evaluate a termination block after evaluating the receiver, regardless of whether the receiver's evaluation completes. | Note |
ifCurtailed: aBlock |
Evaluate the receiver with an abnormal termination action. | Note |
on: exception do: handlerAction |
Evaluate the receiver in the scope of an exception handler. | Note |
Examples
["target code, which may abort"]
ensure:
["code that will always be executed
after the target code,
whatever whatever may happen"]
["target code, which may abort"]
ifCurtailed:
["code that will be executed
whenever the target code terminates
without a natural return"]
["target code, which may abort"]
on: Exception
do:
[:exception |
"code that will be executed whenever
the identified Exception is signaled."]
["target code, which may abort"]
on: Exception, Error, ZeroDivide
do:
[:exception |
"code that will be executed whenever
any of the identified Exceptions are
signaled."]
Class Exception
A far better description is deserved???
Exception is an abstract class. Instances should neither be created nor trapped.
In most cases, subclasses should inherit from Error or Notification rather than directly from
Exception.
exceptionSignaler for Exception
Message |
Description |
Notes |
signal |
Signal the occurrence of an exceptional condition. | Note |
signal: signalerText |
Signal the occurrence of an exceptional condition with a specified textual description. | Note |
signaledException for Exception
Message |
Description |
Notes |
isNested |
Determine whether the current exception handler is within the scope of another handler for the same exception. | Note |
outer |
Evaluate the enclosing exception action for the receiver and return. | Note |
pass |
Yield control to the enclosing exception action for the receiver. | Note |
resignalAs: replacementException |
Signal an alternative exception in place of the receiver. | Note |
resume |
Return from the message that signaled the receiver. | Note |
resume: resumptionValue |
Return the argument as the value of the message that signaled the receiver. | Note |
retry |
Abort an exception handler and re-evaluate its protected block. | Note |
retryUsing: alternativeBlock |
Abort an exception handler and evaluate a new block in place of the handler's protected block. | Note |
return |
Return nil as the value of the block protected by the active exception handler. | Note |
return: returnValue |
Return the argument as the value of the block protected by the active exception handler. | Note |
exceptionDescription for Exception
Message |
Description |
Notes |
defaultAction |
The default action taken if the exception is signaled. | Note |
description |
Return a textual description of the exception. | Note |
isResumable |
Determine whether an exception is resumable. | Note |
messageText |
Return an exception's message text. | Note |
tag |
Return an exception's tag value. | Note |
Class ExceptionSet
An ExceptionSet is a grouping of exception handlers which acts as a single handler.
Within the group, the most recently added handler will be the last handler found
during a handler search (in the case where more than one handler in the group is
capable of handling a given exception).
exceptionSelector for ExceptionSet
Message |
Description |
Notes |
, anException |
Return an exception set that contains the receiver and the argument exception.
This is commonly used to specify a set of exception selectors for an exception handler. | Note |
The Squeak Class Hierarchy
In Smalltalk, "everything is an object."
(That is, everything is an instance of Object or an instance of some subclass of class Object.)
Everything. Numbers, classes, metaclasses, everything. I refer to this as the "Object rule."
Unlike Smalltalk, however, Squeak permits plural disjoint hierarchies of objects,
which permits some remarkable magic. On the other hand, the Object rule does not apply for
certain system objects, which derive from class ProtoObject.
Nevertheless, except for these few system objects, the vast majority of Squeak objects,
which I call, "proper objects," satisfy the Object Rule. Proper Objects and their classes
and metaclasses, satisfy the following properties.
The Laws of Proper (Smalltalk) Classes
- Every proper class is a subclass of class Object, except for Object itself,
which has no proper superclass.
In particular, Class is a subclass of ClassDescription,
which is a subclass of Behavior which is a subclass of Object.
In Squeak, class Object has an improper superclass, named ProtoObject.
- Every object is an instance of a class.
- Every class is an instance of a metaclass.
- All metaclasses are (ultimately) subclasses of Class.
- Every metaclass is an instance of MetaClass.
- The methods of Class and its superclasses support the behavior common to those objects that are classes.
- The methods of instances of MetaClass add the behavior specific to particular classes.
Class ProtoObject
Squeak additionally supports an improper class ProtoObject, from which object hierarchies other
than proper instances and proper classes can be derived. ProtoObject, the improper subclass of
class object has no instances. Indeed, attempting to instantiate ProtoObject will likely result in a crash.
However, as with proper classes, ProtoObject, is an instance of a metaclass, ProtoObject class,
which in turn is an instance of class MetaClass. Presently, there are two subclasses of ProtoObject besides Object:
ObjectOut and ImageSegmentRootStub.
Categories of Squeak Classes
Of course, this quick reference only scratches the surface of the functionality available through Squeak. To assist the beginner in surveying the system, the following outline, or roadmap, of the Squeak system is provided.
Category |
Description |
Kernel |
Primary Smalltalk classes for creating and manipulating Smalltalk objects, the Object hierarchy, coroutines and parallel processes. Subcategories include: Objects, Classes, Methods and Processes. |
Numeric |
Classes for numeric operations, but include date and time operations. Subcategories include: Magnitudes and Numbers |
Collections |
Classes for aggregations of Smalltalk objects. |
Graphics |
Core classes for Smalltalk graphic objects as well as facilities and applications for operating on graphic objects. Key classes include Form and BitBlt. |
Interface |
The "traditional" MVC User Interface Framework. Also found here are a number of useful Smalltalk applications, including: Squeak browsers, a mail client, a web browser, irc chat client and facilities for operating on "projects." |
Morphic |
Squeak's Version of the Morphic User Interface Framework |
Music |
Classes supporting Squeak's Sound Synthesis capabilities. Also found here are several useful facilities and applications for manipulating MIDI data and other representations of musical scores. |
System |
Key System Facilities. Subclasses include: Compiler (Smalltalk compiler); Object Storage (virtual memory for Smalltalk objects); File facilities; Compression; Serial Data Transmission; Basic network facilities. |
Exceptions |
Class supporting Squeak's ANSI-compliant exceptions facilities. |
Network |
Classes implementing various Internet and Squeak related network protocols. |
PluggableWebServer |
A complete web-server application, including an implementation of SWIKI, a collaborative world-wide-web environment. Key classes include: PWS |
HTML |
Classes for manipulating HTML data. |
Squeak |
Here lives the mouse. Key classes include: the Squeak VM and an interpreter; the Squeak Smalltalk Subset (Slang) to C translator; and facilities for developing native plugins (pluggable primitives). |
Balloon |
Classes for complex 2-D graphic objects and fast 2-D graphics rendering. |
Balloon-3D |
Classes for complex 3-D graphics objects and fast 3-D graphics rendering. |
TrueType |
Classes for manipulating and displaying TrueType data. |
MM-Flash |
Classes for manipulating and displaying Flash file data. |
Alice & Wonderland |
A remarkable interactive 3-D graphics application. |