I'm having trouble understanding the '>>' in some Smalltalk programs, Such as this, from Smalltalk By Example:
MyClass>>doThis array := Array new: 3. array at: 1 put: 2.
I can understand that we are creating a new 3-place instance of Array, named array, and putting 2 in the first slot. But I don't understand what MyClass,
, or doThis are doing.
Hi Another Dave,
the >> is used in an informal printout (or in code snippets posted), like in
UndefinedObject(Object)>>doesNotUnderstand: #asTraitComposition
Do this in a workspace: (nil asTraitComposition) and you'll get lots of >> printed out.
But when using >> as message selector,
(Object>>#doesNotUnderstand:) inspect
results in the CompiledMethod.
HTH.
/Klaus
On Thu, 30 Nov 2006 02:42:20 +0100, Another Dave wrote:
I'm having trouble understanding the '>>' in some Smalltalk programs, Such as this, from Smalltalk By Example:
MyClass>>doThis array := Array new: 3. array at: 1 put: 2.
I can understand that we are creating a new 3-place instance of Array, named array, and putting 2 in the first slot. But I don't understand what MyClass,
, or doThis are doing.
(nil asTraitComposition) print it returns a MessageNotUnderstood dialog.
(Object>>#doesNotUnderstand:) print it returns a System Window(3891), and a CompiledMethod dialog.
I'm probably being too literal, or too dense?
Dave normally
is not part of a method definition.
Just the what is after it. in the browser.
is used by authors to give contextual information.
Now in Squeak you can do
Point>>#x to get the compiled method x of class Point but this is query the meta information of classes.
Stef
On 30 nov. 06, at 06:32, Another Dave wrote:
(nil asTraitComposition) print it returns a MessageNotUnderstood dialog.
(Object>>#doesNotUnderstand:) print it returns a System Window (3891), and a CompiledMethod dialog.
I'm probably being too literal, or too dense?
-- View this message in context: http://www.nabble.com/%3E%3E-notation- tf2729086.html#a7613900 Sent from the Squeak - Beginners mailing list archive at Nabble.com.
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
stephane ducasse wrote:
Dave normally
is not part of a method definition.
Just the what is after it. in the browser.
is used by authors to give contextual information.
Now in Squeak you can do
Point>>#x to get the compiled method x of class Point but this is query the meta information of classes.
Stef
Stephane, bless you for all the great work you have done in teaching Smalltalk!
I'm not anywhere near the level to appreciate Point>>#x yet. I'm still grappling with what you mean by "contextual information".
You mention the browser, how would I use it to understand the MyClass>>doThis statement? Or is this even a good example for understanding ">>"?
Stephane, bless you for all the great work you have done in teaching Smalltalk!
I'm not anywhere near the level to appreciate Point>>#x yet. I'm still grappling with what you mean by "contextual information".
You mention the browser, how would I use it to understand the MyClass>>doThis statement? Or is this even a good example for MyClass>>understanding ">>"?
What he means is >> is just something people do when they write about Smalltalk code. Smalltalk code isn't written in files like in other languages, it's written in a class browser, so you can't just say
class SomeClass { void Method(){ //some code } }
So, by convention, when writing code in a text based format like email, Smalltalk'ers simply put the class name before the method name and separate them with >>
SomeClass>>method "some code"
It's not something you would actually do in code... Only when writing about code. In code, you'd simply browse to the SomeClass class, select a method category, and then edit the empty method template, or choose an existing method to edit.
Ramon Leon http://onsmalltalk.com
ANSI Smalltalk defines a format for file-outs and file-ins. I don't understand it well enough to be able to comment, except that it might be defined there.
-Kyle H
On 11/30/06, Ramon Leon ramon.leon@allresnet.com wrote:
Stephane, bless you for all the great work you have done in teaching Smalltalk!
I'm not anywhere near the level to appreciate Point>>#x yet. I'm still grappling with what you mean by "contextual information".
You mention the browser, how would I use it to understand the MyClass>>doThis statement? Or is this even a good example for MyClass>>understanding ">>"?
What he means is >> is just something people do when they write about Smalltalk code. Smalltalk code isn't written in files like in other languages, it's written in a class browser, so you can't just say
class SomeClass { void Method(){ //some code } }
So, by convention, when writing code in a text based format like email, Smalltalk'ers simply put the class name before the method name and separate them with >>
SomeClass>>method "some code"
It's not something you would actually do in code... Only when writing about code. In code, you'd simply browse to the SomeClass class, select a method category, and then edit the empty method template, or choose an existing method to edit.
Ramon Leon http://onsmalltalk.com
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Dave
You mention the browser, how would I use it to understand the MyClass>>doThis statement? Or is this even a good example for understanding ">>"?
MyClass>>doThis is not a statement of the Smalltalk language it is just notation, a way to say (or write) the contents (or definition) of a method.
When you write:
MyClass>>doThis array := Array new: 3. array at: 1 put: 2.
It means that if you browse to the class MyClass, then to the method whose selector is #doThis you will find:
doThis array := Array new: 3. array at: 1 put: 2.
Another example, if I include in a mail the following text:
String>>sameAs: aString "Answer whether the receiver sorts equal to aString. The collation sequence is ascii with case differences ignored." ^(self compare: aString caseSensitive: false) = 2
It means that I am (may be) asuming that the class String exists, that it has a method whose selector is #sameAs: and it's definition is:
sameAs: aString "Answer whether the receiver sorts equal to aString. The collation sequence is ascii with case differences ignored." ^(self compare: aString caseSensitive: false) = 2
Try it, go and find the method sameAs: of the class String.
I hope this helps.
Emilio
You will also sometimes see something like:
Person class >> new
When someone is writing about code. This means that you should look on the class side of Person for the method #new. People will also indicate the method name with a symbol (for example #new) if they are writing the method name in-lined in a sentence.
Ron Teitelbaum President / Principal Software Engineer US Medical Record Specialists Ron@USMedRec.com
-----Original Message----- From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners- bounces@lists.squeakfoundation.org] On Behalf Of Emilio Oca Sent: Thursday, November 30, 2006 1:16 PM To: A friendly place to get answers to even the most basic questionsaboutSqueak. Subject: RE: [Newbies] >> notation
Dave
You mention the browser, how would I use it to understand the MyClass>>doThis statement? Or is this even a good example for understanding ">>"?
MyClass>>doThis is not a statement of the Smalltalk language it is just notation, a way to say (or write) the contents (or definition) of a method.
When you write:
MyClass>>doThis array := Array new: 3. array at: 1 put: 2.
It means that if you browse to the class MyClass, then to the method whose selector is #doThis you will find:
doThis array := Array new: 3. array at: 1 put: 2.
Another example, if I include in a mail the following text:
String>>sameAs: aString "Answer whether the receiver sorts equal to aString. The collation sequence is ascii with case differences ignored." ^(self compare: aString caseSensitive: false) = 2
It means that I am (may be) asuming that the class String exists, that it has a method whose selector is #sameAs: and it's definition is:
sameAs: aString "Answer whether the receiver sorts equal to aString. The collation sequence is ascii with case differences ignored." ^(self compare: aString caseSensitive: false) = 2
Try it, go and find the method sameAs: of the class String.
I hope this helps.
Emilio
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
On 11/30/06, Another Dave dooright101@yahoo.com wrote:
I'm having trouble understanding the '>>' in some Smalltalk programs, Such as this, from Smalltalk By Example:
MyClass>>doThis array := Array new: 3. array at: 1 put: 2.
I can understand that we are creating a new 3-place instance of Array, named array, and putting 2 in the first slot. But I don't understand what MyClass,
, or doThis are doing.
The ">>" is just a way of indicating that you're talking about a message name.
In your example, MyClass is the class name, and doThis is the message name. You'll never actually enter the ">>" when defining a message, instead you'd put the code in the doThis message of MyClass in the browser.
Regards, Stuart.
Stuart Herring wrote:
The ">>" is just a way of indicating that you're talking about a message name.
In your example, MyClass is the class name, and doThis is the message name. You'll never actually enter the ">>" when defining a message, instead you'd put the code in the doThis message of MyClass in the browser.
Regards, Stuart.
Thanks, Stuart for your reply. I should understand by now. There must be something very simple I am missing, because the ">>" symbol is used almost in passing in the early chapters of many tutorials.
In the example:
MyClass>>doThis 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?
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.
Last, I do not understand how the MyClass>>doThis of the above example relates in any way to the second and third lines.
In the example:
MyClass>>doThis 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)".
happy squeaking!
Joe Koberg joe at osoft dot us
1. The class creation message looks like this:
Object subclass: #FooClass instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' 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| a := argument. ^ a * a. '.
parsedMethod := (Compiler new) compile: methodText in: FooClass notifying: nil ifFail: nil.
rawMethod := parsedMethod generate.
FooClass addSelector: #squareFoo: withMethod: rawMethod
beginners@lists.squeakfoundation.org