鲜为人知的Smalltalk二进制消息及其含义?

时间:2017-01-19 18:45:25

标签: smalltalk pharo squeak

为初学者写一些文档,我遇到了一个问题。知道二进制消息的作用,并不意味着你知道它们被称为什么!

一些显而易见的,以及他们各自的课程:

    -   "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

不太明显的:

*=  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

2 个答案:

答案 0 :(得分:3)

>>  Behavior TBehavior Integer TraitBehavior

不是真正的二元,因为它的参数不是同一类型。 它从行为(接收器)投射一个方法,用符号(参数)命名

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

忘了他们,太具体了解那些类

==  ProtoObject

身份比较,it was discussed in a recent question

~~  ProtoObject

这是对==

的否定
%   Number

模数运算符(整数除法的余数)

&   Collection RBBrowserEnvironment Integer ZnUrl RBAbstractCondition False Boolean True

它是和布尔运算符,位二进制和整数的运算符,但对于集合它有不同的含义

+=  ThirtyTwoBitRegister FloatArray
/=  FloatArray

它们就像C运算符一样,操作修改接收器而不是生成新的浮点数组

\\  Collection Number LargeInteger SmallInteger Duration Point

对于幅度,它是整数除法的余数。它对集合有不同的含义。

@   "returns a point?" 

仅针对numbres,它对其他类有不同的含义

我省略了那些我不知道的内容

答案 1 :(得分:3)

让我用更多这些选择器补充Carlos's answer

~= SmallFloat64 SmallInteger Object BoxedFloat64

...是对平等比较的否定=

-> Object

...是一个简洁的方法来建立一个关键值对。写x -> y并获取一个关联实例,其中x为键,y为值。它们用于实现Dictionary。

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

...是a)将对象放入Stream的简写。 aStream << anObject应相当于aStream nextPut: anObjectaStream nextPutAll: anObject,具体取决于参数的类型。可能看起来很熟悉C ++开发人员。

...和b)将整数位向左移位的二进制消息。所以你可能已经猜到了......

>> Behavior TBehavior Integer TraitBehavior

...除了Carlos写的关于从行为中获取方法的内容之外,它也是Integers的右移运算符。

==> Boolean

...是合乎逻辑的含义,这意味着false ==> x总是回答为真,true ==> y回答y。

请注意,其他一些消息(例如**)在Squeak中默认不会实现。

在Pharo中,**raisedTo:的二进制消息别名,所以它将接收器提升到参数的幂(5 ** 3 = 125),就像在Python中一样其他语言。