10.5. Useful Selectors
This is a list of selectors which Selfers should find useful as a starting point.
10.5.1. Copying
| clone |
shallow copy (for use within an object; clients should use copy) |
| copy |
copy the receiver, possibly with embedded copies or initialization |
10.5.2. Comparing
10.5.2.1. Equality
| = |
equal |
| != |
not equal |
| hash |
hash value |
| == |
identical (the same object; this is reflective and should be avoided) |
| !== |
not identical |
10.5.2.2. 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 |
10.5.3. 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 |
10.5.4. Bitwise operations (integers)
| && |
and |
| || |
or |
| ^^ |
xor |
| complement |
bitwise complement |
| << |
logical left shift |
| >> |
logical right shift |
| <+ |
arithmetic left shift |
| +> |
arithmetic right shift |
10.5.5. Logical operations (booleans)
| && |
and |
| || |
or |
| ^^ |
xor |
| not |
logical complement |
10.5.6. 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 |
10.5.7. Printing
| print |
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 |
10.5.8. Control
10.5.8.1. Block evaluation
| value[: {With: }] |
evaluate a block, passing arguments |
10.5.8.2. 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 |
10.5.8.3. 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 |
10.5.8.4. 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 |
10.5.8.5. 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 |
10.5.8.6. 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 |
10.5.8.7. 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 |
10.5.9. Collections
10.5.9.1. Sizing
| isEmpty |
test if collection is empty |
| size |
return number of elements in collection |
10.5.9.2. 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 |
10.5.9.3. 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 |
10.5.9.4. 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 |
10.5.9.5. 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 |
10.5.9.6. 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 |
10.5.9.8. 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 |
10.5.9.9. 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 |
10.5.10. 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 |
10.5.11. Message Sending
10.5.11.1. 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 |
10.5.11.2. 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 |
10.5.12. 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 |
10.5.13. 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) |
10.5.14. 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 |
10.5.15. Virtual Machine-Generated
10.5.15.1. 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 |
10.5.15.2. Other system-triggered messages
| postRead |
slot to evaluate after reading a snapshot |