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. > > > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
(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 > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Another Dave
On 11/30/06, Another Dave <[hidden email]> 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. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
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 reply to this post by stephane ducasse
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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Another Dave
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 [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Another Dave
> 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 mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Emilio Oca
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 [hidden email] > -----Original Message----- > From: [hidden email] [mailto:beginners- > [hidden email]] 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 > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Ramon Leon-5
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 <[hidden email]> 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 > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > -- -Kyle H _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Another Dave
[Newbies] >> notation
Hi Dave, Your being great. I'm learning a lot from following this thread. Thanks for raising the questions persistantly. (Did this using a fresh 3.9 7067) In a workspace try evaluating (with doit or print it) Object>>#doesNotUnderstand:) inspect . an inspector will pop up. Select all bytecodes and see what a squeak method is made of. To make things in squeak using a browser first get a browser In the work space type Object select t and type cmd-b (I'm on a mac translate what I say for your platform) a system window labeled 'System Browser: Object'. In the second column Object is highlighted. Position the mouse over it and Option-click. ( a menu pops up) select 'more...' and then subclasstemplate. In the big text pane at the bottom you will see:: Object subclass: #NameOfSubclass instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Objects' modify this to: Object subclass: #MyClass instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'DavesStuff' Mouse over what you have written and option-click to get the menu from the menu select 'accept it' You have now defined a class myclass. In the third column select --all-- Now the big text pane at the bottom says: message selector and argument names "comment stating purpose of message" | temporary variable names | statements modify that to: doThis "heres what to do" array := Array new: 3. array at: 1 put: 2. and accept it (see above) first a box comes up asking for your initials type them in and click accept. second a menu comes up asing about what to do with array. select 'declare temp' you have now defined the method MyClass>>doThis. Going back to the workspace type myInstance := MyClass new . myInstance doThis select both lines and option-click from the menu select 'print it' you will see the result highlighted it will say a MyClass. thats because the instance as written does not explicitly return a value. so it is returning the receiver. the receiver is the instance of MyClass which we stored in myInstance. go back to the browser add to the end of the method the line ^array go back to the workspace and do the 'print it' again for the same text selection and the result is: #(2 nil nil) Which show what doThis did. in the workspace again type: (MyClass>>#doThis) inspect select and print it. and you will get the inspector window on the complied version of your method. go back to the browser mouse over the highlighted item in each column from the option-click menu select 'fileout' for each column. And look at your image's home directory to see what you get. Yours in service, -- Jerome Peace >Another Dave dooright101 at yahoo.com >Thu Nov 30 05:32:12 UTC 2006 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? > ____________________________________________________________________________________ Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |