简体   繁体   English

图形的GUI定义中@符号的含义?

[英]Meaning of @-sign in GUI definition of a shape?

For instance, in the Lessphic Tutorial (page 6), the following is written: 例如,在“ Lessphic教程” (第6页)中,写了以下内容:

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? 它是具有x和y坐标的点吗? This notation perhaps originated in morphic. 这种表示法可能起源于语素。 But “@-sign” is difficult to google. 但是“ @ -sign”很难用谷歌搜索。

Even though one might be confused by the use of symbols like @ , + , = , etc., and think of them as reserved (ie, known to the compiler), in Smalltalk all of them are selectors of regular methods. 尽管可能会因为使用@+=等符号而感到困惑,并认为它们是保留符号(即编译器已知的符号),但在Smalltalk中,它们都是常规方法的选择器。 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 in Number , usually implemented as @的特殊情况下,如果我们搜索实现者,则会在Number找到一个,通常实现为

@ aNumber
  ^Point x: self y: aNumber

(In Pharo, however, there is a primitive for speeding things up, which is not needed otherwise) (但是,在Pharo中,有一个加快速度的原语,否则就不需要)

The reason for this message is to provide a less verbose Point creation method, so that the client only has to write, say 200 @ 300 , instead of Point x: 200 y: 300 . 该消息的原因是提供了一种不太冗长的Point创建方法,以便客户端只需要写200 @ 300 ,而不是Point x: 200 y: 300

Note by the way that this pattern is pretty common in Smalltalk. 顺便说一下,这种模式在Smalltalk中非常普遍。 Some few questions ago in this [smalltalk] tag we discussed the message / which is a shortcut of the same sort: 2 / 3 is equivalent to (Fraction numerator: 2 denominator: 3) reduced . 之前在这个[smalltalk]标签中,我们讨论了消息/ ,这是同类的捷径: 2 / 3等效于(Fraction numerator: 2 denominator: 3) reduced Other examples include 'hello world' readStream for ReadStream on: 'hello world' , '234.5' asNumber for Number readFromString: '234.5' , etc., etc. 其他示例包括'hello world' readStreamReadStream on: 'hello world''234.5' asNumber for Number readFromString: '234.5'等,等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM