Useful Selectors¶
This is a list of selectors which Selfers should find useful as a starting point.
Copying
clone | shallow copy (for use within an object; clients should use copy) |
copy | copy the receiver, possibly with embedded copies or initialization |
Comparing
Equality
= | equal |
!= | not equal |
hash | hash value |
== | identical (the same object; this is reflective and should be avoided) |
!== | not identical |
Ordered
< | less than |
> | greater than |
<= | less than or equal |
>= | greater than or equal |
compare: IfLess: Equal: Greater: | three way comparison |
compare: IfLess: Equal: Greater: Incomparable: | three way comparison with failure |
Numeric operations
+ | add |
- | subtract |
* | multiply |
/ | divide |
/= | divide exactly (returns float) |
/~ | divide and round to integer (tends to round up) |
/+ | divide and round up to integer |
/-% | divide and round down to integer modulus |
absoluteValue | absolute value |
inverse | multiplicative inverse |
negate | additive inverse |
ceil | round towards positive infinity |
floor | round towards negative infinity |
truncate | truncate towards zero |
round | round |
asFloat | coerce to float |
asInteger | coerce to integer |
double | multiply by two |
quadruple | multiply by four |
half | divide by two |
quarter | divide by four |
min: | minimum of receiver and argument |
max: | maximum of receiver and argument |
mean: | mean of receiver and argument |
pred | predecessor |
predecessor | predecessor |
succ | successor |
successor | successor |
power: | raise receiver to integer power |
log: | logarithm of argument base receiver, rounded down to integer |
square | square |
squareRoot | square root |
factorial | factorial |
fibonacci | fibonacci |
sign | signum (-1, 0, 1) |
even | true if receiver is even |
odd | true if receiver is odd |
Bitwise operations (integers)
&& | and |
|| | or |
^^ | xor |
complement | bitwise complement |
<< | logical left shift |
>> | logical right shift |
<+ | arithmetic left shift |
+> | arithmetic right shift |
Logical operations (booleans)
&& | and |
|| | or |
^^ | xor |
not | logical complement |
Constructing
@ | point construction (receiver and argument are integers) |
# | rectangle construction (receiver and argument are points) |
## | rectangle construction (receiver is a point, argument is an extent) |
& | collection construction (result can be converted into collection) |
, | concatenation |
Printing
print object on stdout | |
printLine | print object on stdout with trailing newline |
printString | return a string label |
printStringDepth: | return a string label with depth limitation request |
printStringSize: | return a string label with number of characters limitation request |
printStringSize: Depth: | return a string label with depth and size limitation request |
Control
Block evaluation
value[: {With: }] | evaluate a block, passing arguments |
Selection
ifTrue: | evaluate argument if receiver is true |
ifFalse: | evaluate argument if receiver is false |
ifTrue: False: | evaluate first arg if true, second arg if false |
ifFalse: True: | evaluate first arg if false, second arg if true |
Local exiting
exit | exit block and return nil if block’s argument is evaluated |
exitValue | exit block and return a value if block’s argument is evaluated |
Basic looping
loop | repeat the block forever |
loopExit | repeat the block until argument is evaluated; then exit and return nil |
loopExitValue | repeat the block until argument is evaluated; then exit and return a value |
Pre-test looping
whileTrue | repeat the receiver until it evaluates to true |
whileFalse | repeat the receiver until it evaluates to false |
whileTrue: | repeat the receiver and argument until receiver evaluates to true |
whileFalse: | repeat the receiver and argument until receiver evaluates to false |
Post-test looping
untilTrue: | repeat the receiver and argument until argument evaluates to true |
untilFalse: | repeat the receiver and argument until argument evaluates to false |
Iterators
do: | iterate, passing each element to the argument block |
to: By: Do: | iterate, with stepping |
to: Do: | iterate forward |
upTo: By: Do: | iterate forward, without last element, with stepping |
upTo: Do: | iterate forward, without last element |
downTo: By: Do: | reverse iterate, with stepping |
downTo: Do: | reverse iterate |
Collections
Sizing
isEmpty test | if collection is empty |
size | return number of elements in collection |
Adding
add: | add argument element to collection receiver |
addAll: | add all elements of argument to receiver |
at: Put: | add key-value pair |
at: Put: IfAbsent: | add key-value pair, evaluating block if key is absent |
addFirst: | add element to head of list |
addLast: | add element to tail of list |
copyAddAll: | return a copy containing the elements of both receiver and argument |
copyContaining: | return a copy containing only the elements of the argument |
Removing
remove: | remove the given element |
remove: IfAbsent: | remove the given element, evaluating block if absent |
removeAll | remove all elements |
removeFirst | remove first element from list |
removeLast | remove last element from list |
removeAllOccurences: | remove all occurrences of this element from list |
removeKey: | remove element at the given key |
removeKey: IfAbsent: | remove element at the given key, evaluating block if absent |
copyRemoveAll | return an empty copy |
Accessing
first | return the first element |
last | return the last element |
includes: | test if element is member of the collection |
occurrencesOf: | return number of occurences of element in collection |
findFirst: IfPresent: IfAbsent: | evaluate present block on first element found satisfying criteria, absent block if no such element |
at: | return element at the given key |
at: IfAbsent: | return element at the given key, evaluating block if absent |
includesKey: | test if collection contains a given key |
Iterating
do: | iterate, passing each element to argument block |
doFirst: Middle: Last: IfEmpty: | iterate, with special behavior for first and last |
doFirst: MiddleLast: IfEmpty: | iterate, with special behavior for first |
doFirstLast: Middle: IfEmpty: | iterate, with special behavior for ends |
doFirstMiddle: Last: IfEmpty: | iterate, with special behavior for last |
reverseDo: | iterate backwards through list |
with: Do: | co-iterate, passing corresponding elements to block |
Reducing
max | return maximum element |
mean | return mean of elements |
min | return minimum element |
sum | return sum of elements |
product | return product of elements |
reduceWith: | evaluate reduction block with elements |
reduceWith: IfEmpty: | evaluate reduction block with elements, evaluating block if empty |
Transforming
asByteVector | return a byte vector with same elements |
asString | return a string with same elements |
asVector | return a vector with same elements |
asList | return a list with the same elements |
filterBy: Into: | add elements that satisfy filter block to a collection |
mapBy: | add result of evaluating map block with each element to this collection |
mapBy: Into: | add result of evaluating map block with each element to a collection |
Sorting
sort | sort receiver in place |
copySorted | copy sorted in ascending order |
copyReverseSorted | copy sorted in descending order |
copySortedBy: | copy sorted by custom sort criteria |
sortedDo: | iterate in ascending order |
reverseSortedDo: | iterate in descending order |
sortedBy: Do: | iterate in order of custom sort criteria |
Indexable-specific
firstKey | return the first key |
lastKey | return the last key |
loopFrom: Do: | circularly iterate, starting from element n |
copyAddFirst: | return a copy of this collection with element added to beginning |
copyAddLast: | return a copy of this collection with element added to end |
copyFrom: | return a copy of this collection from element n |
copyFrom: UpTo: | return a copy of this collection from element n up to element m |
copyWithoutLast | return a copy of this collection without the last element |
copySize: | copy with size n |
copySize: FillingWith: | copy with size n, filling in any extra elements with second arg |
Timing
realTime | elapsed real time to execute a block |
cpuTime | CPU time to execute a block |
userTime | CPU time in user process to execute a block |
systemTime | CPU time in system kernel to execute a block |
totalTime | system + user time to execute a block |
Message Sending
Sending (like Smalltalk perform; receiver is a string)
sendTo: {With: } | send receiver string as a message |
sendTo: WithArguments: | indirect send with arguments in a vector |
sendTo: DelegatingTo: {With: } | indirect delegated send |
sendTo: DelegatingTo: WithArguments: | indirect delegated send with arg vector |
resendTo: {With: } | indirect resend |
resendTo: WithArguments: | indirect resend with arguments in a vector |
Message object protocol
send | perform the send described by a message object |
fork | start a new process; the new process performs the message |
receiver: | set receiver |
selector: | set selector |
methodHolder: | set method holder |
delegatee: | set delegatee of the message object |
arguments: | set arguments (packaged in a vector) |
receiver: Selector: | set receiver and selector |
receiver: Selector: Arguments: | set receiver, selector, and arguments |
receiver: Selector: Type: Delegatee: MethodHolder: Arguments: | set all components |
Reflection (mirrors)
reflect: | returns a mirror on the argument |
reflectee | returns the object the mirror receiver reflects |
contentsAt: | returns a mirror on the contents of slot n |
isAssignableAt: | tests if slot n is an assignable slot |
isParentAt: | tests if slot n is a parent slot |
isArgumentAt: | tests if slot n is an argument slot |
parentPriorityAt: | returns the parent priority of slot n |
slotAt: | returns a slot object representing slot n |
contentsAt: | returns the contents of the slot named n |
visibilityAt: | returns a visibility object representing visibility of slot n |
System-wide Enumerations (messages sent to the oddball object browse)
all[Limit: ] | returns a vector of mirrors on all objects in the system (up to the limit) |
referencesOf: [Limit: ] | returns a vector of mirrors on all objects referring to arg (up to the limit) |
referencesOfReflectee: [Limit: ] | returns a vector of mirrors on all objects referring to argument’s reflectee (up to the limit); allows one to find references to a method |
childrenOf: [Limit: ] | returns a vector of mirrors on all objects with a parent slot referring to the given object (up to the limit) |
implementorsOf: [Limit: ] | returns a vector of mirrors on objects with slots whose names match the given selector (up to the limit) |
sendersOf: [Limit: ] | returns a vector of mirrors on methods whose selectors match the given selector (up to the limit) |
Debugging
halt | halt the current process |
halt: | halt and print a message string |
error: | halt, print an error message, and display the stack |
warning: | beep, print a warning message, and continue |
Virtual Machine-Generated
Errors
undefinedSelector: Type: Delegatee: MethodHolder: Arguments: | lookup found no matching slot |
ambiguousSelector: Type: Delegatee: MethodHolder: Arguments: | lookup found more than one matching slot |
missingParentSelector: Type: Delegatee: MethodHolder: Arguments: | parent slot through which resend was delegated was not found |
performTypeErrorSelector: Type: Delegatee: MethodHolder: Arguments: | first argument to the _Perform primitive was not a canonical string |
mismatchedArgumentCountSelector: Type: Delegatee: MethodHolder: Arguments: | number of args supplied to _Perform primitive does not match selector |
primitiveFailedError: Name: | the named primitive failed with given error string |
Other system-triggered messages
postRead | slot to evaluate after reading a snapshot |