How to use the method compile in smalltalk and what parameters can I call it with

1k views Asked by At

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"
1

There are 1 answers

6
Sean DeNigris On BEST ANSWER

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)