For instance, in the Lessphic Tutorial (page 6), the following is written:
aShape := ShapedView withShape: (0@0 corner: 100@100).
aShape := (0@0 corner: 100@100) shapedView.
What does “@” mean? Is it a point with x and y coordinates? This notation perhaps originated in morphic. But “@-sign” is difficult to google.
Even though one might be confused by the use of symbols like
@,+,=, etc., and think of them as reserved (i.e., known to the compiler), in Smalltalk all of them are selectors of regular methods. In other words, they are not reserved tokens but valid selectors of messages that (in most of the cases) implement the expected behavior.In the particular case of
@, if we search for implementors we will find one inNumber, usually implemented as(In Pharo, however, there is a primitive for speeding things up, which is not needed otherwise)
The reason for this message is to provide a less verbose
Pointcreation method, so that the client only has to write, say200 @ 300, instead ofPoint x: 200 y: 300.Note by the way that this pattern is pretty common in Smalltalk. Some few questions ago in this [smalltalk] tag we discussed the message
/which is a shortcut of the same sort:2 / 3is equivalent to(Fraction numerator: 2 denominator: 3) reduced. Other examples include'hello world' readStreamforReadStream on: 'hello world','234.5' asNumberforNumber readFromString: '234.5', etc., etc.