Question on copying methods.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Question on copying methods.

jdelgado
Hi,

My name is Jordi Delgado and I am currently working, on my spare time, on
the translation of a Squeak application to Catalan (yes, I know that I would
need to translate all of Squeak to call it a real translation, but this is
far from what my spare time allows me to do). I am working with version
3dot8gamma update #6662, not with version 3dot9. Unfortunately, this is not
optional.

I would be very grateful if someone could give an understandable explanation
of what follows (I've tried hard to make sense of it, but I'm afraid
I don't know yet enough Smalltalk, or Squeak):

Let us assume I want to copy a method in a class, but changing its name.
For example, in version 3dot9 I would do:

Number  addAndClassifySelector: #absolute
        withMethod: (Number compiledMethodAt: #abs)
        inProtocol: #arithmetic
        notifying: nil

to copy the abs method with the name 'absolute' in category 'arithmetic'
of class 'Number'. And that would work as intended. I mean, browsing class
Number, protocol arithmetic, one can see the method 'absolute' with the
following source code:

Number>>absolute
        "Answer a Number that is the absolute value (positive magnitude)
         of the receiver"

        self < 0
                ifTrue:  [^ self negated]
                ifFalse: [^ self]

that's it, exactly what was expected.

The problem with version 3dot8gamma is that doing the same thing, one does not
get the same result. What is obtained is a method of name 'absolute', according
to the browser, but the code is:

Number>>abs
        "Answer a Number that is the absolute value (positive magnitude)
         of the receiver"

        self < 0
                ifTrue:  [^ self negated]
                ifFalse: [^ self]

that is, the correct method but the wrong name (it keeps 'abs' instead of
changing it to 'absolute', as it should do). One still can edit the source
code but with a previous warning, since the names (the one in the code and the
one in the browser) should be the same.

Somehow I don't think this is a question for the beginners list, so I submit
it here. Please, let me apologize in advance if this is a silly question.

Thanks a lot in advance for your answers. And thanks a lot for this list,
it is a valuable source to learn Smalltalk.

Bests

Jordi