List of Useful Selectors
Introduction
The following is just a keyword list to give you a hint what to search for.
Use the SystemBrowser to find
implementors
or
senders
of those messages.
Looking at the comments in the implementors will give you more information about
what is done in those methods; looking at the senders code, you will learn more
on how those messages are typically used.
Notice that the browser supports wildcard searches - thus you can search for
patterns such as "at*" or even "n*ut*".
A note to beginners:
what you see below is NOT smalltalk syntax, but a small fraction of messages
understood by classes in the system; there is much more.
For smalltalk syntax and the basic classes/messages, see
If you are new to Smalltalk and used to other programming languages,
many binary selectors may look like syntax to you.
Beside the obvious "+", "-" etc. the most
noteworthy are "," (concatenation), "?" (default value), "@" (point instantiation)
and "=>" (association instantiation). These are names for operations just like
the others and are implemented as methods of their respective receiver classes
(to the left of the operator).
Also, you will find demonstration code and examples for some concepts
in the directory "doc/coding"
. All classes also contain
a documentation category and many have an examples method there.
A step-by-step introduction into the view classes is found
in the document 'introduction to view programming'.
In the list below, the characters '[' and ']' mean:
optional;
thus:
foo:[bar:]
means that both methods for foo:
and foo:bar:
are provided.
(for beginners: this means that there are two methods in the system:
foo:
and foo:bar:
)
This list is far from complete, currently there are about 40000 methods
(try Method instanceCount
)
in more than 4500 classes
(try Class allSubInstances size
)
to be found in the base system alone
(not counting some additional goodies, demos etc. and many autoloaded methods).
It should be clear that the list
below is only a very small extract.
Happy browsing ...
PS: a very useful tool to find which message delivers a given result,
is theMethodFinder.
Most Useful Selectors
Creating Objects
new | - message to a class - returns a new (typically initialized) instance |
new: |
- (usually a ) message to a container class.
Returns a container instance of (preallocated) size
|
basicNew |
- message to a class - returns a new definitely uninitialized instance
|
Copying Objects
shallowCopy |
- shallow copy (the copy references the same objects)
|
deepCopy |
- deep copy (referenced objects are also deep-copied)
Handles recursive and self-referencing structures. |
copy |
- usually defaults to a shallow copy
|
General Queries
class |
- return an object's class
|
respondsTo: |
- ask if message is understood
|
isMemberOf: |
- ask if instance of a class (not recommended)
|
isKindOf: |
- ask if instance of a class or subclass (not recommeneded)
|
isNil |
- true if object is nil
|
notNil |
- true if object is not nil
|
isClass |
- true if object is a class
|
isNumber |
- true if object is a number
|
isXXXX |
- some more of this
|
respondsToArithmetic |
- true if object understands arithmetic messages
|
|
|
allOwners |
- returns a collection of objects referencing the receiver
|
allInstances |
- returns a collection of a class's instances
|
allDerivedInstances |
- returns a collection of a class's and subclass's instances
|
Comparing
General
== |
- identical; i.e. the same object
|
~~ |
- not identical
|
= |
- equal; i.e. same structure and value(s)
|
~= |
- not equal
|
hash |
- return a key for hashing
|
identityHash |
- return a key for hashing on identity
|
Magnitudes
> |
- greater than
|
>= |
- greater or equal
|
< |
- less than
|
<= |
- less or equal
|
|
|
between:and: |
- test if in a range
|
min: |
- minimum
|
max: |
- maximum
|
Arithmetic (Numbers)
+ |
- addition
|
- |
- difference
|
* |
- product
|
/ |
- division - tends to convert to float
|
// |
- truncating division - returns integer
|
\\ |
- modulo
|
|
|
abs |
- absolute value
|
negated |
- negated value (0 - receiver)
|
|
|
rounded |
- round to nearest integer
|
truncated |
- truncate towards zero
|
ceiling |
- round toward positive infinity
|
floor |
- round toward negative infinity
|
|
|
asFloat |
- coerce to float
|
asInteger |
- coerce to integer (i.e. truncates)
|
|
|
log: |
- logarithm
|
sin |
- sine
|
cos |
- cosine
|
raiseTo: |
- raise to power
|
sqrt |
- square root
|
|
|
even |
- true if even
|
odd |
- true if odd
|
sign |
- signum (-1, 0, 1)
|
positive |
- true if positive
|
negative |
- true if negative
|
Bitwise Operations (Integers)
bitAnd: |
- bitwise and
|
bitOr: |
- bitwise or
|
bitXor: |
- bitwise exclusive or
|
bitInvert |
- bitwise complement
|
bitShift: |
- shift
|
Logical Operations (Booleans)
& |
- logical and (evaluating)
|
| |
- logical or (evaluating)
|
not |
- logical not
|
|
|
and: |
- logical and (non evaluating)
|
or: |
- logical or (non evaluating)
|
Collections
Sizing
size |
- number of elements
|
isEmpty / notEmpty |
- true/false if collection is empty
|
isEmptyOrNil / notEmptyOrNil |
- true/false if receiver is empty or nil
|
Adding
add: |
- add a new element
|
addAll: |
- add all elements of argument
|
at:put: |
- store element into collection
|
atAllPut: |
- fill
|
atAll:put: |
- fill parts
|
addFirst: |
- add at beginning
|
addLast: |
- add at end
|
Removing
remove:[ifAbsent:] |
- remove an element [with opt. error handler]
|
removeAll: |
- remove all
|
removeFirst |
- remove first element
|
removeLast |
- remove last element
|
removeKey: |
- remove a key
|
Accessing
at: |
- retrieve at index/key
|
at:ifAbsent: |
- retrieve, with handler if index is absent
|
first |
- retrieve first element
|
last |
- retrieve last element
|
Testing
includes: |
- true if element is in the collection
|
includesIdentical: |
- not just the same - but that particular object
|
includesAny: |
- true if any is in the collection
|
includesAll: |
- true if all are in the collection
|
occurrencesOf: |
- return number of occurrences of an element
|
includesKey: |
- return true if key is valid
|
indexOf:[ifAbsent:] |
- search and return position using = (indexable collections)
|
identityIndexOf:[ifAbsent:] |
- search and return position using == (indexable collections)
|
Iterating
do: |
- enumerate collection elements
|
keysAndValuesDo: |
- same, but pass keys and values to block
|
reverseDo: |
- in reverse order
|
collect: |
- enumerate elements, collect results
|
select:[ifNone:] |
- enumerate elements, collect some elements
|
reject: |
- enumerate elements, collect some elements
|
inject:into: |
- enumerate and accumulate some result
|
findFirst: |
- find first/last element for which a check returns true
|
findLast: |
|
with:do: |
- enumerate two collections in one loop
|
with:collect: |
|
contains: |
- check if any element applies
|
Converting
asArray |
- return an array with the same elements
|
asOrderedCollection |
- return an orderedCollection with the same elements
|
asSortedCollection |
- return a sortedCollection with the same elements
|
asSet |
- return a set with the same elements
|
asBag |
- return a bag with the same elements
|
readStream |
- return a stream to read the elements
|
writeStream |
- return a stream to write into the collection
|
Sorting
sort[:] |
- inplace sort [with optional sort criteria]
|
topologicalSort[:] |
- full search (slow) [with optional sort block]
|
reverse |
- reverse elements order
|
Copy (Copy & Replace - Non Destructive)
copyFrom: |
- copy to the end
|
copyTo: |
- copy from beginning
|
copyFrom:to: |
- copy part
|
copyWith: |
- copy and append
|
copyWithout: |
- copy and remove
|
copyWithoutIndex: |
- copy and remove (indexable collections)
|
copyWithoutLast: |
- copy except last elements
|
|
|
copyReplaceFrom:[to:][with:][startingAt:] |
- copy and replace in the copy
|
|
|
copy |
- copy all
|
deepCopy |
|
shallowCopy |
|
Replacing (Destructive)
replaceFrom:[to:][with:][startingAt:] |
- replace elements
|
replaceAll:by: |
- search & replace
|
String Specials
, |
- concatenation
|
|
|
paddedTo:[with:] |
- padding [with optional fill character]
|
leftPaddedTo:[with:] |
|
|
|
asUppercase |
- copy and make copy uppercase
|
asLowercase |
- copy and make copy lowercase
|
asUppercaseFirst |
- copy and make the first character uppercase
|
|
|
asNumber |
- read number from string
|
asFilename |
- convert to a filename
|
|
|
match: |
- (simple) regular expression match
|
startsWith: |
- query for prefix
|
endsWith: |
- query for suffix
|
findString:[startingAt:[ifAbsent:]] |
- substring search
|
spellAgainst |
- spelling difference
|
|
|
sameAs: |
- compare ignoring case
|
|
|
countWords |
- simple scanning
|
asCollectionOfWords |
- separate into individual words
|
asCollectionOfLines |
- separate at line boundaries
|
asCollectionOfSubstringsSeparatedBy: |
- separate at other boundaries
|
|
|
withoutSpaces |
- copy & remove leading & trailing spaces
|
withoutSeparators |
- copy & remove leading & trailing whitespace
|
|
|
indexOfSeparator[StartingAt:] |
- search for any whitespace
|
indexOfNonSeparator |
- search for non whitespace
|
|
|
asStringWith:from:to:compressTabs:final:- |
concatenate many strings
|
Printing & Storing
Printing
printOn: |
- basic low level object printing
Does NOT output quotes around strings, so it can be used directly to print into a file. |
|
|
print |
- print receiver on standard output (Stdout)
|
printCR |
- same, followed by a newline
|
|
|
errorPrint |
- print receiver on standard error (Stderr)
|
errorPrintCR |
- same, followed by a newline
|
|
|
infoPrint |
- like above; can be turned off with --infoPrint
|
infoPrintCR |
- same, followed by a newline
|
|
|
printString |
- returns a string for printing (uses #printOn:)
|
displayString |
- same as printString, but used when <anObject>
is to be shown in a view (such as an inspector). Different from printString in some classes. |
|
|
printStringRadix: |
- integers) returns a printString in different radix
|
|
|
Number |
displayRadix: - set the default radix used in displayString
|
Formatted Printing
printOn:paddedTo:[with:] |
- print and pad output on the right
[with optional fill character] |
printOn:leftPaddedTo:[with:] |
- print and pad output on the left
|
printStringPaddedTo:[with:] |
- return a right padded printstring
|
printStringLeftPaddedTo:[with:] |
- return a left padded printstring
|
bindWith:[with:[with:]] |
- slice printStrings into a format string
|
Storing
storeOn: |
- store a textual representation.
Warning: this is slow, creates huge files and does not handle self references. |
readFrom: |
- retrieve an object stored with 'storeOn:'
|
|
|
storeBinaryOn: |
- stores <anObject> in a binary representation
(handles recursive and self referencing objects) |
readBinaryFrom: |
- retrieves an object stored with 'binaryStoreOn:'
|
Object Dependencies
addDependent: |
- make another object be a dependent
|
removeDependent: |
- remove a dependent
|
dependents |
- get dependents
|
changed:[with:] |
- notify dependents of a change
|
broadcast:[with:] |
- broadcast a message
|
update:[with:][from:] |
- sent to dependents
|
onChangeSend:to: |
- send a particular message on change
|
onChangeEvaluate: |
- evaluate a block on change
|
Debugging
Log Messages
Logger |
- defaults to a Transcript logger; can be changed
|
Logger info:[with:...] |
- generate an info message in the log
|
Logger warn:[with:...] |
- generate a warning message in the log
|
Logger error:[with:...] |
- generate an error message in the log
|
Logger trace:[with:...] |
- generate a trace message in the log
|
Transcript messages
Transcript show: |
- shows an object's printString on the Transcript
|
Transcript showCR: |
- same, but appends a carriage return (line end)
|
Transcript cr |
- only appends a carriage return (line end)
|
Transcript flash |
- wakeup the user
|
Transcript clear |
- clear the Transcript
|
Alerts
warn: |
- pops up a warning box - suppressible
|
information: |
- pops up an information box - suppressible
|
notify: |
- pops up a notifier - not suppressible
|
confirm: |
- asks yes/no questions
|
Debugging
halt |
- raise halt signal - usually ends in debugger
|
halt: |
- halt with message
|
error |
- raise error signal - usually ends in debugger
|
error: |
- error with message
|
assert: |
- assert that some condition is true
|
|
|
inspect |
- to have a deeper look into any object
|
basicInspect |
|
Advanced Debugging
MessageTracer trace:selector: |
- to trace sends of a selector to an object
|
MessageTracer trap:selector: |
- to trape send of a selector to an object
|
MessageTracer untrap:[selector:] |
- remove trace or trap
|
|
|
MessageTally spyOn: |
- execution profile
|
MessageTally spyDetailOn: |
- same, with higher clock resolution
|
Special Object Manipulations
instSize |
- returns number of named instance variables
|
instVarAt: |
- returns a named instance variable (do not use)
|
instVarAt:put: |
- set a named instance variable (never use)
|
|
|
become: |
- become another object - and vice versa
|
becomeSameAs: |
- one-way become
|
becomeNil |
- effectively destroy an object
|
|
|
changeClassTo: |
- for dynamic inheritance
|
Handling Errors
handle:do: |
- define a signal handler for an evaluation
handler does #return, #returnWith:, #restart or #resume (see Exception) |
catch: |
- catch signals while evaluating (i.e. abort execution)
|
ignore: |
- catch signals and continue evaluation
|
|
|
handlerBlock: |
- defines a handler block for a signal
|
|
|
ex return[:] |
- return from an exception [with optional value]
|
ex restart |
- restart execution after an exception
|
ex proceed[With:] |
- continue execution from an exception [with optional value]
|
|
|
signal raise |
- raise an exception
|
signal isHandled |
- query if currently handled
|
|
|
Object doesNotUnderstandSignal |
- some common signals
|
Number divisionByZeroSignal |
|
Float domainErrorSignal |
|
PipeStream brokenPipeSignal |
|
Socket brokenConnectionSignal |
|
Object abortSignal |
|
|
|
Object noHandlerSignal |
- raised for unhandled signals
|
|
|
Object errorSignal |
- parent of all signals handling this one als handles all others
|
Number arithmeticSignal |
- parent of all arithmetic signals
|
Queries & Notifications
answer:do: |
- answer a query inside a block evaluation
|
query |
- request an answer from someone above in the
calling hierarchy |
QuerySignal default: |
- define a default answer to a query
|
Program Control
Basic Control
ifTrue:[ifFalse:] |
- simple if
|
ifFalse:[ifTrue:] |
|
|
|
whileTrue: |
- loop test at entry
|
whileFalse: |
|
|
|
whileTrue |
- condition only
|
whileFalse |
|
|
|
doUntil: |
- loop test at end
|
doWhile: |
|
|
|
loop |
- loop forever
|
loopWithExit |
- and with exit
|
|
|
timesRepeat: |
- counted loop
|
|
|
to:[by:]do: |
- loop with index
|
|
|
do: |
- loop over elements of a collection
|
keysAndValuesDo: |
- loop with index & element
|
reverseDo: |
- the other way
|
? |
- nil check; used with lazy initialized variables
|
Evaluating Blocks
value |
- evaluate without
|
value:[value:[value:]] |
- evaluate with arguments (up to 4)
|
valueWithArguments: |
- evaluate with arguments from an array
|
valueWithExit |
- evaluate with exit possibility
|
valueOnUnwindDo: |
- with cleanup actions on unwind
|
valueNowOrOnUnwindDo: |
- with cleanup in any case
|
valueUninterruptably |
- evaluate with interrupts blocked
|
Message Sending / Method Evaluation
perform:[with:[with:]] |
- perform; for non-constant selector sends
|
perform:withArguments: |
- with arguments from an array
|
perform:ifNotUnderstood: |
- save perform with handler
|
perform:inClass:withArguments: |
- perform, with class for lookup (super-send)
|
Processes (also called "threads")
Creation
fork |
- create a process to execute in parallel
|
forkAt:prio |
- with any priority
|
newProcess |
- create, but don't run
|
|
|
Processor activeProcess |
- get the current process
|
Processor activePriority |
- get the current priority
|
Control
suspend |
- suspend a process
|
resume |
- resume a process
|
terminate |
- terminate a process
|
terminateNoSignal |
- quick terminate a process
|
priority[:] |
- get/set priority
|
|
|
interruptWith: |
- interrupt a process
|
Semaphores, SharedQueues and Delays
wait[WithTimeout:] |
- suspend process to wait on semaphore [with optional timeout]
|
signal |
- wakeup processes waiting on semaphore
|
signalIf |
- wakeup, but only if being waited upon
|
signalOnce |
- signal, but only if count is zero
|
|
|
critical: |
- critical regions (mutual exclusion)
|
|
|
next |
- controlled access to sharedQueues
|
nextPut: |
|
|
|
Delay forSeconds: |
- create a Delay object
|
Delay forMilliseconds: |
|
|
|
wait |
- suspend process to wait on delay
|
resume |
- premature wakeup of a delay
|
Accessing the Context Chain
thisContext |
- the context of the current method
(this is not a message, but a pseudo variable) |
thisContext |
sender - the caller's context
|
return[:] |
- return from a context (with value); no cleanup
|
restart |
- restart a context
|
resume |
- continue execution in a context
|
unwind[:] |
- return from context with cleanup actions
|
Files (Filenames)
asFilename |
- convert string to filename
|
|
|
exists |
- check existence of a file
|
isReadable |
- check if readable
|
isDirectory |
- check if directory
|
|
|
copyTo: |
- copy a file
|
renameTo: |
- rename a file
|
remove |
- remove a file or directory (must be empty)
|
delete |
- remove a file (ST-80 compatibility)
|
recursiveRemove |
- remove a directory and all of its contents
|
|
|
filesMatching: |
- match filenames
|
filenameCompletion |
- search for best match
|
|
|
directoryContents |
- ask directory for its entries
|
contentsOfEntireFile |
- get all of a file's contents
|
|
|
|
|
makeDirectory |
- create a new directory
|
Filename newTemporary |
- create unique temporary file names in /tmp
|
Filename newTemporaryIn: |
- create unique temporary file names somewhere
|
File- and Stream-I/O
FileStream oldFileNamed: |
- open an existing file
|
FileStream readonlyFileNamed: |
- open read-only
|
FileStream newFileNamed: |
- open/create for writing
|
|
|
aFilename readStream |
- stream on a file (given the name) for reading
|
aFilename writeStream |
- for writing
|
|
|
aCollection readStream |
- stream on a collection for reading
|
aCollection writeStream |
- for writing
|
|
|
binary |
- read bytes (as opposed to characters)
|
|
|
atEnd |
- check for end-of-stream
|
Reading
next[:] |
- read next (n) element(s)
|
|
|
peek |
- look ahead
|
nextPeek |
- read and look ahead
|
peekFor: |
- look ahead and compare
|
|
|
upTo: |
- read up to some element
|
upToEnd |
- read till end is reached
|
|
|
skip: |
- skip
|
skipFor: |
- skip up to
|
skipThrough: |
- skip up to and including
|
skipAny: |
- skip all from a collection
|
skipToAll: |
- skip until arg matches (string search)
|
Writing
nextPut: |
- append an element
|
next:put: |
- append an element repeated
|
nextPutAll:[startingAt:to:] |
- append (part of) a collection
|
ExternalStream Specials
readWait[WithTimeout:] |
- wait for data to become available for reading
|
writeWait[WithTimeout:] |
- wait until write is possible without blocking
|
|
|
canReadWithoutBlocking |
- check for data being available for reading
|
canWriteWithoutBlocking |
- check if write is possible
|
|
|
ioctl:[with:] |
- perform ioctl
|
blocking: |
- turn on/off blocking I/O
|
buffered: |
- turn on/off buffered I/O
|
Reading/Writing Character Streams
nextLine |
- read a line (external streams)
|
nextWord |
- read a word (external streams)
|
nextChunk |
- read a chunk in fileIn format (external streams)
|
|
|
nextPutLine: |
- append a line plus newline character
|
|
|
peekForLineStartingWith: |
- search for & return next matching line
|
peekForLineStartingWithAny: |
- same, but match any of a collection
|
|
|
upToSeparator |
- read up to next whitspace (character streams)
|
|
|
skipSpaces |
- skip all spaces (character streams)
|
skipSeparators |
- skip whitespace (character streams)
|
skipSeparatorsExceptCR |
- skip whitespace, stop at line end (character streams)
|
skipLine |
- skip one line (i.e. up to newline)
|
Reading/Writing Binary Data
nextByte |
- read a byte
|
nextShortMSB: |
- read a signed short (2 bytes) specifying msb or lsb
|
nextUnsignedShortMSB: |
- read an unsigned short (2 bytes) specifying msb or lsb
|
nextLongMSB: |
- read a signed long (4 bytes) specifying msb or lsb
|
nextUnsignedLongMSB: |
- read an unsigned long (4 bytes) specifying msb or lsb
|
nextBytes:into: |
- read some bytes
|
|
|
nextPutByte: |
- write a byte
|
nextPutShort:MSB: |
- write a signed short (2 bytes), specifying msb or lsb
|
nextPutLong:MSB: |
- write a signed long (4 bytes), specifying msb or lsb
|
nextPutBytes:from: |
- write some bytes
|
List of Most Useful Classes
Collection |
- protocol should be known; most other
collections implement part or all of its protocol. |
|
|
OrderedCollection |
- most often used indexable collection
|
Array |
- second most often used indexable collection
|
String |
- it's all about text
|
Set |
- often overlooked by beginners
|
Dictionary |
- often overlooked by beginners
|
|
|
|
|
Number |
- common protocol for all numbers
|
|
|
Stream |
- common protocol for both, internal and
|
ExternalStream |
external streams
|
|
|
Filename |
- implements all kinds of filename queries
|
|
|
Block |
- all control structures use them;
if you understand blocks, you understand Smalltalk ;-) |
|
|
Process |
- threads and synchronization
|
Semaphore |
|
Delay |
|
List of Interesting Globals
Smalltalk |
- contains all globals (name<->object associations)
|
|
|
Logger |
- to repord depug/info/warning messages
(configurable to redirect the output) |
|
|
Transcript |
- to send informal messages to the user
|
|
|
Stdout |
- standard output stream (i.e. xterm or console)
|
Stderr |
- standard error stream (i.e. xterm or console)
|
Stdin |
- standard input stream (i.e. xterm os console)
|
|
|
Display |
- default display Workstation
|
(Screen current) |
- current display (use with multi display applications)
|
|
|
Processor |
- for process scheduling
|
|
|
OperatingSystem |
- for system queries
|
Copyright © 1995 Claus Gittinger, all rights reserved
<cg at exept.de>
Doc $Revision: 1.38 $ $Date: 2021/03/13 18:24:51 $