Restricting super calls to inherited method

Richard A. O'Keefe ok at atlas.otago.ac.nz
Mon May 21 03:26:44 UTC 2001


Paul Fernhout <pdfernhout at kurtz-fernhout.com> wrote:
    String>>alike: aString 
        "Answer some indication of how alike the receiver is to the argument, 
         0 is no match, twice aString size is best score.  Case is ignored."
    
        | i j k minSize bonus |
        minSize := (j := self size) min: (k := aString size).
        bonus := (j - k) abs < 2 ifTrue: [ 1 ] ifFalse: [ 0 ].
        i := 1.
        [(i <= minSize) and: [((super at: i) bitAnd: 16rDF)  = ((aString at: i)
                                ^^^^^^^^^^^
    asciiValue bitAnd: 16rDF)]]
            whileTrue: [ i := i + 1 ].
        [(j > 0) and: [(k > 0) and:
            [((super at: j) bitAnd: 16rDF) = ((aString at: k) asciiValue bitAnd:
               ^^^^^^^^^^^
    16rDF)]]]
                whileTrue: [ j := j - 1.  k := k - 1. ].
        ^ i - 1 + self size - j + bonus. 
    
    I'm not sure yet why either of these methods needs to call "super"
    instead of self.

I can tell you why String>>alike: is doing it.
In String, self at: i returns a character, while super at: i returns an
integer.  In this case, "self basicAt: i" would do the job perfectly,
basicAt: is primitive 60 and super at: turns out to be Object>>at: which
is also primitive 60.  String>>byteAt: (also primitive 60) would also work.

This is not a good example of using 'super'!

By the way, there *must* be an easy way in a Browser to say
"show me this method and all the inherited versions of it, rather like
 versions (v) but a different source for the methods".
But I can't figure out what it is.  Browse hierarchy gives me a hierarchy
for the entire class.





More information about the Squeak-dev mailing list