If my understanding is right then you cannot send a message to an object passed as a parameter to a method of another class.
Is this correct ?
What about messages to instance variables ?
Have I lost it, or is this correct ?
Aaron
On Sun, 5 Dec 2004 04:21:38 -0000, Aaron Gray angray@beeb.net wrote:
If my understanding is right then you cannot send a message to an object passed as a parameter to a method of another class.
Is this correct ?
What about messages to instance variables ?
Have I lost it, or is this correct ?
Why not show us a sample of what you mean.
If my understanding is right then you cannot send a message to an object passed as a parameter to a method of another class.
Why not show us a sample of what you mean.
Okay :-)
class B anotherMethod: self doSomething:
class A aMethod: aParam aParam anotherMethod:
That is probably not legal SmallTalk from what I understand on the VM ?
Or are method names unique ?
Aaron
On Sun, 5 Dec 2004 05:20:31 -0000, Aaron Gray angray@beeb.net wrote:
If my understanding is right then you cannot send a message to an object passed as a parameter to a method of another class.
Why not show us a sample of what you mean.
Okay :-)
class B anotherMethod: self doSomething: class A aMethod: aParam aParam anotherMethod:
That is probably not legal SmallTalk from what I understand on the VM ?
Or are method names unique ?
Now, convert it into something like what is below and paste it into a browser (the body should be valid syntax) and see what is the result?
======= B>>anotherMethod self doSomething A>>aMethod: aParam aParam anotherMethod =======
On Sun, Dec 05, 2004 at 05:20:31AM -0000, Aaron Gray wrote:
If my understanding is right then you cannot send a message to an object passed as a parameter to a method of another class.
Why not show us a sample of what you mean.
Okay :-)
class B anotherMethod: self doSomething: class A aMethod: aParam aParam anotherMethod:
That is probably not legal SmallTalk from what I understand on the VM ?
Or are method names unique ?
Hi Aaron,
Please try the following. It will take you about a half hour to do this the first time, but I think you will be glad to have spent the time once you have done it.
Make a new project:
world menu -> open... -> morphic project
The new project will appear as a box with a label like "Unnamed2". Click on the box to enter the project.
Open a browser and a workspace. Click on Tools flap (on the right side of the screen). Use the mouse to drag a Browser onto your screen, then do the same for a Workspace (you can also create these using the world menu -> open...).
In your browser, experiment with your mouse buttons to see what they do. On my computer (Linux), the left button selects things, middle button brings up menus, and right button brings up the "Morphic halos" (little buttons around the Morphs that make up your browser). On Windows, the right button does the menu things, but I'll just refer to "middle button" in what follows.
Make a new class category called "My Junk". In the upper left pane of the browser (the one with the list of Kernel-Objects, Kernel-Classes, etc), middle button click for menu, then "add item...". In the category name prompt that comes up, type "My Junk", then click Accept.
Now in the large bottom pane of the browser, you can create your new class. Where it now says "Object subclass: #NameOfSubclass", change it to say "Object subclass: #MyTestClassB", then accept the text to create the class. You can accept the text with keyboard <alt>s, or middle button click and "select" from the menu.
MyTestClassB will show up in the second-from-left pane in the browser. Underneath this, click the "?" button. The class comment entry area appears in the bottom pane. Replace the text with a comment such as "This is my test class B." Accept the text. (I'm just telling you this part so you will be in the habit of doing it. Think of it as a note to yourself explaining why you created the class, just in case you need to remember it six months from now.)
Now click on the third-from-left pane, the one that says "no messages". Do middle button click, then select "new category...". Select "new...", then enter "my test methods" as your catagory. (Again, this is just to get in the habit of putting things in categories that will mean something to you six months from now).
Now you can enter a method. In the bottom pane, there is some example text that suggests the layout of the method source code. Replace this with your actual method, then accept it. Your actual method can look like this (the underscore character will be a left-arrow when you type it into Squeak):
anotherMethod: aParameter "This method does something with aParameter, but for now it will just halt so I can see it in a debugger." | myTempVar | myTempVar _ aParameter. self halt. "self doSomething might go here" ^ myTempVar
Now you have your class B. You can give it a #doSomething: method also if you want to have your #anotherMethod do a "self doSomething: aParam"
Now make another class called MyTestClassB. Give it a method like this:
aMethod: aParam "This method does something with aParam"
| myFirstTempVar | myFirstTempVar _ aParam. self halt. ^ myFirstTempVar
Now you can experiment and see how things really work. Go to your workspace (the white window), and enter the following to get started:
anInstanceOfB _ MyTestClassB new. anInstanceOfA _ MyTestClassA new. anInstanceOfB anotherMethod: anInstanceOfA.
Accept this text in the workspace (<alt>s), then highlight it with the mouse. Middle button click, and select "inspect it".
Your code will start running, and stop with a red "Halt" dialog when it reaches a "self halt" in your code. Click the "Debug" button to go into the debugger and see what is happening. (Note: You can also run code in the debugger just by putting a "self halt" in the text on the workspace, right before the code you want to evaluate).
In the top pane of the debugger, you will see levels of the execution stack. Click on the second from the top, where you see the "myTestClassB>>anotherMethod:", and you will now see your source code in the middle pane.
In the lower right debugger pane, enter the text "myTempVar aMethod: self". Highlight your text, then middle button click, and "Inspect" it. You will get another halt dialog to put you into another debugger, which will show the result of sending your instance of MyTestClassB as a parameter for the #aMethod message sent to MyTestClassA.
Now it's time to start exploring and experimenting. I won't try to explain how to use the debugger, just start clicking on things and see what's what. You have experience with other languages, so it will probably make sense to you right away. Smalltalk is a stack oriented virtual machine, so it should look familiar if you have worked with Java or anything similar. Just click on levels of the stack (top debugger pane) and experiment to your heart's content with the things in the other debugger panes. Try clicking on things, double clicking on things, and middle button click to see menu options.
You can do *anything* you want right in the debugger, including change your code and proceeding. You can inspect variables and parameters, you can send messages to them, you can see exactly with is "visible" at any point in the execution, and so forth. Try treating the panes at the bottom as little interactive workspaces, and if you want to modify any of the code you are experimenting with, do it right in the big middle code pane.
Have fun,
Dave
p.s. One last thing that might interest you: Go back to your Browser and click on one of your methods so you can see the source code. In the middle of the browser is a row of buttons, click on the one on the far right labelled "source". In the "What to show" dialog, select "byteCodes". Now you are looking at the stuff that matters to the virtual machine.
Okay sorry I have been away for a while.
Now you can enter a method. In the bottom pane, there is some example text that suggests the layout of the method source code. Replace this with your actual method, then accept it. Your actual method can look like this (the underscore character will be a left-arrow when you type it into Squeak):
anotherMethod: aParameter "This method does something with aParameter, but for now it will just halt so I can see it in a debugger." | myTempVar | myTempVar _ aParameter. self halt. "self doSomething might go here" ^ myTempVar
I am getting to this point and the method compiler is responding saying "Argument name expected ->"
Argument name expected ->anotherMethod: aParameter "This method does something with aParameter, but for now it will just halt so I can see it in a debugger." | myTempVar | myTempVar _ aParameter. self halt. "self doSomething might go here" ^ myTempVar
What am I doing wrong ?
Aaron
Does your Browser look similar to the attached? (sorry for the 13k png ...)
On December 5, 2004 04:06 pm, Aaron Gray wrote:
Okay sorry I have been away for a while.
Now you can enter a method. In the bottom pane, there is some example text that suggests the layout of the method source code. Replace this with your actual method, then accept it. Your actual method can look like this (the underscore character will be a left-arrow when you type it into Squeak):
anotherMethod: aParameter "This method does something with aParameter, but for now it will just halt so I can see it in a debugger."
| myTempVar |
myTempVar _ aParameter. self halt. "self doSomething might go here" ^ myTempVar
I am getting to this point and the method compiler is responding saying "Argument name expected ->"
Argument name expected ->anotherMethod: aParameter "This method does something with aParameter, but for now it will just halt so I can see it in a debugger."
| myTempVar |
myTempVar _ aParameter. self halt. "self doSomething might go here" ^ myTempVar
What am I doing wrong ?
Aaron
I am getting to this point and the method compiler is responding saying "Argument name expected ->"
Argument name expected ->anotherMethod: aParameter "This method does something with aParameter, but for now it will just halt so I can see it in a debugger."
| myTempVar |
myTempVar _ aParameter. self halt. "self doSomething might go here" ^ myTempVar
What am I doing wrong ?
Does your Browser look similar to the attached? (sorry for the 13k png ...)
Yes, but it was not Accepting it for some reason, but now it is working fine, retried again and it was fine, so I do not know what I was doing wrong.
I also am finding that I do something in the workspace once and it does not work then doing it again and it does with no obvious difference that I can determine right now, maybe with a bit more experience I will see why.
Aaron
"Aaron Gray" angray@beeb.net wrote:
I also am finding that I do something in the workspace once and it does not work then doing it again and it does with no obvious difference that I can determine right now, maybe with a bit more experience I will see why.
Aaron
One thing worth knowing is that if you do not declare your temporaries in a workspace they will be created as bindings in the workspace, and thus "survive" for later code snippets.
That is the only thing I know that could cause the "same" code to behave differently the next time. Disregarding state in globals of course. :)
regards, Göran
I also am finding that I do something in the workspace once and it does not work then doing it again and it does with no obvious difference that I can determine right now, maybe with a bit more experience I will see why.
One thing worth knowing is that if you do not declare your temporaries in a workspace they will be created as bindings in the workspace, and thus "survive" for later code snippets.
That is the only thing I know that could cause the "same" code to behave differently the next time. Disregarding state in globals of course. :)
I do not think that was it, maybe something to with my use of full stops perhaps although this maybe another issue ?
I did seem to have code that would not compile one minute and would the next, but as I say it may have been my inexperience with SmallTalk and Squeak in general.
Aaron
Le 2004/12/05, Aaron Gray angray@beeb.net écrivait :
Yes, but it was not Accepting it for some reason, but now it is working fine, retried again and it was fine, so I do not know what I was doing wrong.
Hi Aaron, I think you inadvertently hit the 'uppercase' key of your keyboard...is it possible? I noted that on Windows when I can't accept code it is that I'm in uppercase. (wondering the exact term....I don't talk about 'shift' key but the one above it)...
Raymond
Yes, but it was not Accepting it for some reason, but now it is working fine, retried again and it was fine, so I do not know what I was doing wrong.
Hi Aaron, I think you inadvertently hit the 'uppercase' key of your keyboard...is it possible? I noted that on Windows when I can't accept code it is that I'm in uppercase. (wondering the exact term....I don't talk about 'shift' key but the one above it)...
No it was me pressing the Windows <shift><insert> key combination. This generates an uninterpretable invisible character in the Smalltalk text window, and hence was getting error messages.
You mean the Caps Lock key - The Capital letter lock key.
Aaron
Thanks
David,
Its working now, do not know why, but I have tried it again for a new class and it works fine so I do not know what I was doing wrong to get the message "Argument name expected ->" before the method name.
Aaron
On Sun, Dec 05, 2004 at 09:17:43PM -0000, Aaron Gray wrote:
David,
Its working now, do not know why, but I have tried it again for a new class and it works fine so I do not know what I was doing wrong to get the message "Argument name expected ->" before the method name.
Good, that will give you something to experiment with. I can tell from your earlier posts that you have some experience with other languages, so I think you will find Squeak quite interesting once you start poking around in the debugger and tinkering with the gears and levers.
Dave
Good, that will give you something to experiment with. I can tell from your earlier posts that you have some experience with other languages, so I think you will find Squeak quite interesting once you start poking around in the debugger and tinkering with the gears and levers.
Thanks for the introduction,
Aaron
start to read Smalltalk by Example available as free books on my web page....
Online Free Books at http://www.iam.unibe.ch/~ducasse/WebPages/FreeBooks.html
Hi,
start to read Smalltalk by Example available as free books on my web page....
Okay will do soon, I was going to read the SmallTalk language definition when I get round to it. Maybe I will buy SmallTalk by Example as I do prefer books compared to online reading. Thanks, I will have a look at it online first.
Online Free Books at http://www.iam.unibe.ch/~ducasse/WebPages/FreeBooks.html
BTW: You gave me an old redirected URL !
Many thanks, I was sort of waiting for that advice.
Aaron
"Aaron Gray" angray@beeb.net wrote:
Hi,
start to read Smalltalk by Example available as free books on my web page....
Okay will do soon, I was going to read the SmallTalk language definition when I get round to it. Maybe I will buy SmallTalk by Example as I do prefer books compared to online reading. Thanks, I will have a look at it online first.
Ack - pretty please Aaron, try to remember there's no capital T in Smalltalk. A trivial point I suppose but it does grate somewhat to read after so many years.
tim -- Tim Rowledge, tim@sumeru.stanford.edu, http://sumeru.stanford.edu/tim Strange OpCodes: WDS: Warp Drive, Scotty!
Ack - pretty please Aaron, try to remember there's no capital T in Smalltalk. A trivial point I suppose but it does grate somewhat to read after so many years.
Sorry, force of habit after writing all those variable names :)
Smalltalk Smalltalk Smalltalk
There that's better :-)
Aaron
Whoopse, forgot the title !
On Mon, 06 Dec 2004 15:08:52 -0800, Tim Rowledge tim@sumeru.stanford.edu wrote:
Ack - pretty please Aaron, try to remember there's no capital T in Smalltalk. A trivial point I suppose but it does grate somewhat to read after so many years.
Shouldn't it be "smallTalk"?<s>
Smalltalk Smalltalk Smalltalk Smalltalk Smalltalk Smalltalk
----- Original Message ----- From: "Aaron Gray" angray@beeb.net To: "The general-purpose Squeak developers list" squeak-dev@lists.squeakfoundation.org Sent: Monday, December 06, 2004 2:01 PM Subject: Re: SmallTalk Book advice ( was: Smalltalk language limitation ? )
Hi,
start to read Smalltalk by Example available as free books on my web page....
Okay will do soon, I was going to read the SmallTalk language definition when I get round to it. Maybe I will buy SmallTalk by Example as I do
prefer
books compared to online reading. Thanks, I will have a look at it online first.
Online Free Books at http://www.iam.unibe.ch/~ducasse/WebPages/FreeBooks.html
BTW: You gave me an old redirected URL !
Many thanks, I was sort of waiting for that advice.
Aaron
Hi stéphane,
start to read Smalltalk by Example available as free books on my web page.... Online Free Books at http://www.iam.unibe.ch/~ducasse/WebPages/FreeBooks.html
Sorry, but where is the index ?
The introduction to the book says it has a good index, but there seems to be no index ?
Aaron
In the actual new release of the book, there is a problem with the index of the pdf file. Indeed, you have to get look at the sub-index to see chapter titles. I agree that it's so painful that I prefer to use the oldest release...
Cheers, Houssam ____ "Le paradis touche les pieds des mères..."
-----Message d'origine----- De : squeak-dev-bounces@lists.squeakfoundation.org [mailto:squeak-dev-bounces@lists.squeakfoundation.org] De la part de Aaron Gray Envoyé : mardi 7 décembre 2004 17:50 À : The general-purpose Squeak developers list Objet : Re: Smalltalk language - Smalltalk by Example
Hi stéphane,
start to read Smalltalk by Example available as free books on my web page.... Online Free Books at http://www.iam.unibe.ch/~ducasse/WebPages/FreeBooks.html
Sorry, but where is the index ?
The introduction to the book says it has a good index, but there seems to be no index ?
Aaron
But I could not recreate the index...too bad. I also have something else to do.
In the actual new release of the book, there is a problem with the index of the pdf file. Indeed, you have to get look at the sub-index to see chapter titles. I agree that it's so painful that I prefer to use the oldest release...
Cheers, Houssam ____ "Le paradis touche les pieds des mères..."
-----Message d'origine----- De : squeak-dev-bounces@lists.squeakfoundation.org [mailto:squeak-dev-bounces@lists.squeakfoundation.org] De la part de Aaron Gray Envoyé : mardi 7 décembre 2004 17:50 À : The general-purpose Squeak developers list Objet : Re: Smalltalk language - Smalltalk by Example
Hi stéphane,
start to read Smalltalk by Example available as free books on my web page.... Online Free Books at http://www.iam.unibe.ch/~ducasse/WebPages/FreeBooks.html
Sorry, but where is the index ?
The introduction to the book says it has a good index, but there seems to be no index ?
Aaron
On Dec 4, 2004, at 11:21 PM, Aaron Gray wrote:
If my understanding is right then you cannot send a message to an object passed as a parameter to a method of another class. Is this correct ?
No, you can do this. (If I understand you correctly.) In fact, there are probably thousands of methods in Squeak that do this. :-)
I just poked around for a minute in a browser, and the third method I ran across has an example of this. See Rectangle>>areasOutside:. The method is passed an object (parameter) with the name "aRectangle". Down in the method, the message #corner is sent to this parameter.
What about messages to instance variables ?
Not sure what you mean here. If you can get to the instance variable, you can send a message to it. (It is true that you can't reference an object's instance variable directly unless you are "inside" that object. Smalltalk instance variables have the equivalent of "protected" access in C++/Java-speak.)
- Doug
If my understanding is right then you cannot send a message to an object passed as a parameter to a method of another class.
Is this correct ?
No, you can do this. (If I understand you correctly.) In fact, there are probably thousands of methods in Squeak that do this. :-)
Right, I need a good language introduction then. Any suggestions ?
I obviously have alot more to learn about the System-Compiler and VM
Aaron
Right, I need a good language introduction then. Any suggestions ?
I obviously have alot more to learn about the System-Compiler and VM
Aaron
Why?
You can work an entire career in Smalltalk without ever having to do anything directly with the System-Compiler or the VM.
Indeed, I would venture a guess that the vast majority of readers of this list never venture into that territory.
Nevin
Right, I need a good language introduction then. Any suggestions ?
I obviously have alot more to learn about the System-Compiler and VM
Aaron
Why?
I have been studying Virtual Machines and Compiler technologies and have only been looking at SmallTalk for three days so far so forgive my lack of knowledge of SmallTalk and Squeak. I should have read more first and studied the SmallTalk properly before hand and I may have not posed such a silly question !
You can work an entire career in Smalltalk without ever having to do anything directly with the System-Compiler or the VM.
Indeed, I would venture a guess that the vast majority of readers of this list never venture into that territory.
Yep.
Sorry for any disturbance,
Aaron
On Dec 4, 2004, at 8:56 PM, Doug Way wrote:
On Dec 4, 2004, at 11:21 PM, Aaron Gray wrote:
What about messages to instance variables ?
Not sure what you mean here. If you can get to the instance variable, you can send a message to it. (It is true that you can't reference an object's instance variable directly unless you are "inside" that object. Smalltalk instance variables have the equivalent of "protected" access in C++/Java-speak.)
- Doug
Well I'll actually point out that normally if you don't have an accessor method for an instance variable the you shouldn't be able to access that instance variable outside the class But to preserve the sanity of folks who want to something clever we provide a way you can cheat.
Object>>instVarAt: index "Primitive. Answer a fixed variable in an object. The numbering of the variables corresponds to the named instance variables. Fail if the index is not an Integer or is not the index of a fixed variable. Essential. See Object documentation whatIsAPrimitive."
<primitive: 73> "Access beyond fixed variables." ^self basicAt: index - self class instSize
To poke at instance variables that you don't have access to. The reason for doing this usually implies something very clever, say serializling an object to be sent over the internet, or printing the contents of an object on the error log. However, doing this as part of any non-clever drab business program is as you might guess a frowned upon activity...
Aaron I'll point out an instance variable is just a placeholder for any smalltalk object, which could be a number, a Class, an Array, a drab business object. There is no type restrictions or naming conventions that dictate terms/rules. Beyond the acceptable practices that Class variables start with upper case, and rules for how instance variables are named, methods named etc. Again these are all styles the community uses, see "Smalltalk with Style" for the rules. Smalltalk is very clever and flexible, none of the restrictions you are use to in other languages.
Try this link for some free smalltalk books http://www.iam.unibe.ch/~ducasse/FreeBooks.html
-- ======================================================================== === John M. McIntosh johnmci@smalltalkconsulting.com 1-800-477-2659 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com ======================================================================== ===
Hi Aaron --
At 08:21 PM 12/4/2004, Aaron Gray wrote:
If my understanding is right then you cannot send a message to an object passed as a parameter to a method of another class.
Is this correct ?
No. If you have a reference to an object, you can always send it a message. Parameter passing is done by reference, as in LISP. This is not always a good thing if there are multiple tasks, etc.
What about messages to instance variables ?
Ditto.
Have I lost it, or is this correct ?
It's not correct, but you haven't lost it. It's a reasonable thing to find out in any language.
Cheers,
Alan
Aaron
squeak-dev@lists.squeakfoundation.org