Here's a question I feel comfortable asking on the Newbies list. :-)
What's the hash mark signify when used as a prefix to a method name, as in the snippet below?
On 5/12/06, Ralph Johnson johnson@cs.uiuc.edu wrote:
Because instance creation methods are just methods (but on the class, instead of on the instance), you can define as many as you want. Look at class Date. There is #today, #tomorrow, #yesterday, #newDay:year:, #newDay:month:year:, #year:day: #year:month:day:
- Bob Erb
Le Vendredi 12 Mai 2006 23:22, Bob Erb a écrit :
Here's a question I feel comfortable asking on the Newbies list. :-)
What's the hash mark signify when used as a prefix to a method name, as in the snippet below?
On 5/12/06, Ralph Johnson johnson@cs.uiuc.edu wrote:
Because instance creation methods are just methods (but on the class, instead of on the instance), you can define as many as you want. Look at class Date. There is #today, #tomorrow, #yesterday, #newDay:year:, #newDay:month:year:, #year:day: #year:month:day:
- Bob Erb
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Well, #today is a literal constant in Smalltalk syntax. It creates an instance of Symbol. More exactly, it return existing Symbol made of letters #($t $o $d $a $y) because Symbol are some special String that are unique in the image (a kind of optimization of space with efficient equality testing).
When you send a message to an object, the selector of the message is a Symbol. This Symbol will be used as a look up key in the methodDictionary of receiver's class, so as to find wich method to execute in response to the message send.
So when we write Time class>>today, that means the method with selector #today in class (Time class).
Time class>>today is also the way to print method stack in the debugger. So it is widely used in our mail to designate precisely that method.
But it is not re-interpretable as a Smalltalk expression. This is why we sometimes write Time class>>#today instead, an expression which you should try and inspect.
Lazily, we omit the class side when there are several methods, but we indicate the # to still make clear we are implicitly speaking of a method selector.
Note that (Time class) means that it is a class method, thus you must send the message to the class, not to the instances. Example: Time today
If the method is an instance method, like #monthName, you would write Time>>monthName or Time>>#monthName. Example: (Time today) monthName
Hope this explanation clarify our habits
Nicolas
On 5/12/06, Bob Erb bob.erb@gmail.com wrote:
Here's a question I feel comfortable asking on the Newbies list. :-)
What's the hash mark signify when used as a prefix to a method name,
The hash mark signifies that it is a symbol.
Another word for "method name" is "selector". You sometimes see this in comments in the code. For example, see the method #addSelector:withMethod: in Behavior. A "selector" is always a symbol. This means that the name of a method is always a symbol.
If I were writing a paper on Smalltalk and wanted to mention a method name, I'd probably make it bold face, but when I am using plain ASCII, like in e-mail or a Smalltalk comment, I'll put a hash mark before the method name to indicate that it is a symbol.
-Ralph Johnson
beginners@lists.squeakfoundation.org