[Newbies] >> notation
joe at osoft.us
Thu Nov 30 18:30:31 UTC 2006
> In the example:
> array := Array new: 3.
> array at: 1 put: 2.
> you say that MyClass is the class name, and doThis is the message name. I
> follow so far, even though with the object/message syntax of Smalltalk I
> would expect the arrows to point the other direction. I have learned that we
> don't use classes directly, we use instances of classes. So we couldn't use
> the first line of the above example without doing first:
> foo := MyClass
> so that we could pass whatever message doThis might be. Right? Is doThis
> predefined, or is it somehow being defined in this example?
In Smalltalk, classes aren't defined with a text definition like a
file-based language. Instead, a message is sent to a superclass asking
it to create a subclass (1). Then methods are individually entered in
the Browser, which sends messages to compile and add the method (2).
So there is no simple text syntax that "is" the class/method. This is a
problem if I want to show it to someone on a mailing list, or if I want
to duplicate the class in another image. In any other language I would
just copy and paste it from the source file with syntax intact.
Thus there is a convention that when you talk about method foo in class
FooClass, you refer to it as "FooClass>>foo". I think the convention is
also used in the changeset file format used to move code around.
> Further, I am confused that the ">>" is not a symbol that is input to
> the machine, but rather a symbol that is output to indicate some
> relationship or function (you say message name indicator), yet
> MyClass>>doThis is clearly not merely a comment.
It is not Smalltalk code, just a notation used by programmers and
import/export tools to describe where the code should be.
> Last, I do not understand how the MyClass>>doThis of the above
> example relates in any way to the second and third lines.
It simply says "method doThis in class MyClass is where this code comes
from (or goes)".
joe at osoft dot us
1. The class creation message looks like this:
category: 'Test Classes'
2. When the typed-in method body is "accepted", the browser sends
messages vaugely like the following to create the method:
"in this example the methodText is hardcoded"
methodText := ' squareFoo: argument
a := argument.
^ a * a. '.
parsedMethod := (Compiler new)
rawMethod := parsedMethod generate.
FooClass addSelector: #squareFoo: withMethod: rawMethod
More information about the Beginners