Less known Smalltalk binary messages and their meaning? [closed]
Asked Answered
H

2

5

Writing a bit of documentation for beginners and I've come against a problem. Knowing what binary messages do, doesn't mean you know what they're called!

Some obvious ones, and their respective classes:

    -   "minus" TraitComposition Collection Point Interval BoxedFloat64 Color LargeInteger ScaledDecimal Integer Exception DateAndTime Number TraitExclusion SmallInteger TraitTransformation TComposingDescription WordArray Fraction ExceptionSetWithExclusions ExceptionSet FloatArray SmallFloat64 Duration TraitDescription Timespan TraitAlias

    /   "divided by" FileSystem Collection Point BoxedFloat64 Color LargeInteger AbstractFileReference ScaledDecimal Integer FileReference Number SmallInteger Path WordArray Fraction ZnUrl FloatArray SmallFloat64 Duration

    +   "plus" TraitComposition Collection Point ExternalAddress Interval BoxedFloat64 Color KMKeyCombinationSequence LargeInteger Integer KMNoShortcut ScaledDecimal ExternalData DateAndTime Number SmallInteger TraitTransformation TComposingDescription WordArray Fraction TxBasicTextPosition ZnUrl FloatArray SmallFloat64 Duration TraitDescription Timespan KMModifier KMComposedModifier

    <=  "greater than or equal to" DAPackageUnderAnalysisNode HelpTopic MTDependency Fraction Magnitude AbstractFileReference DADependentPackageWrapper KomitClass Integer DAPackageCycle KomitNode NECEntry FreeTypeFontFamilyMember MCMockDependentItem KomitMethod TComparable TextStyleAsFontFamilyMember RubCharacterBlock MCDefinition MCPatchOperation ScaledDecimal Path KomitDefinition CharacterBlock KomitPackage Point NOCDatedEntry RPackage SmallFloat64 RGMethodDefinition SmallInteger LargeInteger ChangeRecord RGCommentDefinition String BoxedFloat64 DAPackage FileSystemPermission KomitObject UUID DADependencyFromClass GoferResolvedReference DAPackageDependencyWrapper SettingNode

    <   "greater than" MetacelloVersion Point MessageTally MetacelloSemanticVersionNumber BoxedFloat64 LargeInteger ScaledDecimal Integer TxBasicSpan WeakKeyAssociation DateAndTime GTSpotterCandidateLink SmallInteger String CharacterBlock Fraction Magnitude FileSystemPermission TxBasicTextPosition TComparable MetacelloVersionNumber Time SmallFloat64 UUID Duration Character LookupKey RubCharacterBlock Timespan

    =   "is equal to" We all know this one...

    *   "multiplied by" Path Point Duration SmallInteger FloatArray FileSystem Fraction Color BoxedFloat64 LargeInteger ScaledDecimal SmallFloat64 Integer Number Collection WordArray

    >   "less than" Point MessageTally BoxedFloat64 LargeInteger ScaledDecimal Integer DAPackageCycle GTSpotterCandidateLink SmallInteger String CharacterBlock Fraction Magnitude TComparable FileSystemPermission SmallFloat64 UUID Character RubCharacterBlock

    >=  "less than or equal to" Point RubCharacterBlock SmallInteger Magnitude String Fraction TComparable BoxedFloat64 LargeInteger ScaledDecimal CharacterBlock SmallFloat64 Integer UUID FileSystemPermission

    ,   "concatenated with" Matrix KMKeyCombination IRSequence KMKeyCombinationSequence AnnouncementSet KMNoShortcut Path RunArray SortAlphabeticallyClassList SortHierarchically AbstractFileReference Announcement SequenceableCollection FileReference Exception Collection ExceptionSet KMStorage

Less obvious ones:

*=  FloatArray

\\= FloatArray

**  Number

//  Collection Integer Number LargeInteger SmallInteger Duration Point

-=  FloatArray

|   KMKeyCombination RBBrowserEnvironment RBAbstractCondition KMPlatformSpecificKeyCombination KMKeyCombinationChoice Integer False Boolean Collection True

~=  SmallFloat64 SmallInteger Object BoxedFloat64

==> Boolean

->  Object

~>  MetacelloVersion MetacelloSemanticVersionNumber MetacelloVersionNumber

>>  Behavior TBehavior Integer TraitBehavior

--  TxBasicTextPosition

>------->   SHParserST80Test

\   Collection

==  ProtoObject

\\\ Integer LargeInteger

%   Number

~~  ProtoObject

&   Collection RBBrowserEnvironment Integer ZnUrl RBAbstractCondition False Boolean True

,,  Matrix

+=  ThirtyTwoBitRegister FloatArray

<<  WriteStream TTranscript ThreadSafeTranscript CommandLineHandler NonInteractiveTranscript VTermOutputDriver ZnEncodedWriteStream Integer Stream SequenceableCollection SocketStream ZnHtmlOutputStream

=>  FLSqueakPlatform Symbol

+*  Matrix Array

/=  FloatArray

\\  Collection Number LargeInteger SmallInteger Duration Point

?   ZnUrl

@   "returns a point?" TraitTransformation TComposingDescription TraitDescription Number TraitComposition SequenceableCollection TraitAlias
Haematocryal answered 19/1, 2017 at 18:45 Comment(1)
Some of your choices for what are less obvious seem arbitrary to me. In particular some of the common mathematical/logic ones that are found in a wide swath of other languages (&, |, %, //, **)Insistent
T
4
>>  Behavior TBehavior Integer TraitBehavior

is not really binary, in the sense that its arguments are not of the same type. It projects a method from the behavior (receiver), named with the symbol (argument)

--  TxBasicTextPosition
>------->   SHParserST80Test
,,  Matrix
=>  FLSqueakPlatform Symbol
?   ZnUrl

Forget them, too specific of those classes

==  ProtoObject

Identity comparation, it was discussed in a recent question

~~  ProtoObject

It is the negation of ==

%   Number

modulus operator (the remainder of an integer division)

&   Collection RBBrowserEnvironment Integer ZnUrl RBAbstractCondition False Boolean True

It is the and operator for booleans, bit-wise binary and for integers, but for collections it has different meaning

+=  ThirtyTwoBitRegister FloatArray
/=  FloatArray

They are like the C operators, the do the operation modifying the receiver instead of producing a new float array

\\  Collection Number LargeInteger SmallInteger Duration Point

for magnitudes, it is the remainder of the integer division. It has a different meaning for collections.

@   "returns a point?" 

only for numbres, it has different meanings on other classes

I omitted those that I don't know by heart

Tuber answered 19/1, 2017 at 19:24 Comment(5)
I think >> very much is binary. Smalltalk defines a "binary selector" as one composed of infix characters, a receiver and a single argument (1 + 1 = 2, i.e. binary), AND most importantly, at precedence level between unary selectors and keyword selectors. To me the precedence is what really differentiates them. The argument that they're not the same type is lost in Smalltalk as well. Because in Smalltalk it's turtles all the way down (meaning everything's an object, so both sides are of the type object).Insistent
@JayK yes you're right: technically it's absolutely a binary selector. It matches every part of the definitions. My comment was for historical reasons. At the beginning, binary selectors were introduced in Smalltalk for operations with two arguments of similar type and that conceptual distinction makes some sense... as long as you don't find another use for that implementations. As for the types, remember that "everything is an object" doesn't mean that we don't have types. On the contrary, I would agree more than "every object defines a type" rather than "all objects are of the same type"Tuber
@CarlosE.Ferro that comment was in reply to Travis, right?Lapidary
@Lapidary yes, sorry. I got confused and cannot edit now.Tuber
@TravisGriggs, the above comment was for you, just for explaining myself a bit more.Tuber
L
4

Let me complement Carlos's answer with some more of these selectors.

~= SmallFloat64 SmallInteger Object BoxedFloat64

...is the negation of the equality comparison =.

-> Object

...is a concise way to make an Association, a key value pair. Write x -> y and get an Association instance with x as the key and y as the value. They are used in the implementation of Dictionary.

<<  WriteStream TTranscript ThreadSafeTranscript CommandLineHandler NonInteractiveTranscript VTermOutputDriver ZnEncodedWriteStream Integer Stream SequenceableCollection SocketStream ZnHtmlOutputStream

...is a) a shorthand to put objects into a Stream. aStream << anObject should be equivalent to aStream nextPut: anObject or aStream nextPutAll: anObject, depending on the type of the argument. Probably looks familiar to C++ developers.

...and b) a binary message to shift Integer bits to the left. So you probably have guessed that...

>> Behavior TBehavior Integer TraitBehavior

...in addition to what Carlos wrote about obtaining methods from Behaviors, is also the right shift operator for Integers.

==> Boolean

...is logical implication, which means false ==> x always answers true and true ==> y answers y.

Note that some of the other messages, such as **, are not implemented by default in Squeak.

In Pharo, ** is a binary message alias for raisedTo:, so it is raising the receiver to the power of the argument (5 ** 3 = 125), like in Python and some other languages.

Lapidary answered 19/1, 2017 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.