0

I'm trying to add additional functionality to the already defined method "compile" in smalltalk. here is the code I wrote:

compile: code notifying: requestor trailer: bytes ifFail: failBlock 
self log:(self substring: code delimiter: $?).
super compile: code notifying: requestor trailer: bytes ifFail: failBlock.

as you can see compile has 4 parameters, I only know what to give the first parameter when calling the method compile (which is the code as a string).

whatever functionality I added isn't relevant, I'm not able to run any tests for my method because I dont know what to give the last 3 parameters. So my question here is how can i call my method with the right set of parameters.

This is where I got stuck while writing a test for it:

co := ContractObject new.

code := 'rate: aRate
"?This is the Compiler Comment. Log me?"
hourlyRate := aRate. '.

co compile: code. "3 parameters missing here"
Amer Mograbi
  • 489
  • 1
  • 6
  • 18
  • I don't think so. This is just for a homework. – Amer Mograbi Dec 09 '14 at 12:31
  • 2
    @Begueradj: There is a vibrant international Smalltalk community, with particularly strong presence in the U.S., Europe, and South America. In particular, Pharo seems to be heralding its new life - see http://pharo.org/success for some examples in the wild and http://forum.world.st/attachment/4794112/0/TwitterOnSmalltalk.pdf for some buzz (incl. some of programming's heavy hitters) – Sean DeNigris Dec 09 '14 at 12:47

1 Answers1

2

Since you mentioned this is a homework assignment, I will not deprive you of discovering the joys of a live, dynamic system like Smalltalk ;) The best tutor is your image itself. For many messages (including the one in question), there are helpful examples right under your finger tips that can give you clues about how to send them.

To find these real world examples, you "Browse Senders" of the message in question and see how these clients handle the parameters you're confused about. In Squeak (you didn't say which dialect and Pharo doesn't have that message), I see two senders in particular that show how to handle those parameters.

If you don't know how to "browse senders", there are many great references to teach you. For me, "Pharo By Example" is my go-to reference for basic "how do I" questions like yours (or "Squeak By Example" if you're using Squeak). This "fishing pole", if you will, will provide you with faster answers, and more understanding, then begging for fish on SO ;)

n.b. When asking Smalltalk questions, please tag the dialect (e.g. Pharo, Squeak, Amber) because not all dialects have the same set of messages (e.g. Pharo does not have the message you asked about)

Sean DeNigris
  • 6,306
  • 1
  • 31
  • 37
  • Thanks for letting me discover things on my own but I've been stuck for a long while now. Can you elaborate about what you mean exactly by "the two senders in squeak that show how to handle those parameters"? further more, I know that everything is smalltalk is a message to an object so senders are ? – Amer Mograbi Dec 09 '14 at 13:39
  • Senders are "the methods in the image which send the message in question" (with one small caveat that does not apply in your case). Did you check "Squeak By Example"? It explains it quite clearly. I'll give you a hint, since I did not see it in the text - the shortcut is CMD-n. If you need more help, explain which step you're stuck on - e.g. "I highlighted the message and clicked CMD-N, but..." – Sean DeNigris Dec 09 '14 at 14:06
  • ok so I delved into my image (I'm guessing that is my squeak system browser) and found behavior and in it i found different versions of compile in these version they called the compile I need with the set of parameters I was looking for. I tried running it with them but it didnt work, after it i removed every modification of compile from my code and just tried to run their compile without any changes from my side and still got the same error which is DoesNotUnderstand #BitShift. Is this normal?? shouldn't it have worked being it their code? – Amer Mograbi Dec 09 '14 at 19:59
  • Great progress!! Please update your question with the statement you tried with all the parameters so someone can try to recreate the same error. It's difficult to say without seeing the exact code and possibly actually running it... – Sean DeNigris Dec 09 '14 at 20:33
  • I found out what caused the error, I called compile in a wrong way the correct way is "ContractObject class compile: code." now all is left is to find out where to write my new compile method I need to somehow make it override the compile in behavior so i need to find out how to add it to contractObject class because I think then it will override it. – Amer Mograbi Dec 09 '14 at 20:49
  • Great. There could be a few gotchas, but they are too long for a comment, so if you run into trouble, edit your question and I'll add them to my answer – Sean DeNigris Dec 09 '14 at 20:58