Solving the problem of isSomeClass
Aaron J Reichow
reic0024 at d.umn.edu
Sun Jun 15 06:08:08 UTC 2003
Hola again-
A few days ago
Looking at Morph, I see there are 18 methods in the classification
category, all isSomething methods.
Perhaps in DNU: we could implement a check- if the method being called
isn't understood, and 1. begins with "is" and then 2. is followed by
the name of a class (capitalized), return the result of isKindOf:
thatClass.
This may not work with what we have now, but for the thought experiments
I've done so far, it seems to. I imagine someone will think of something
which breaks it. At least methods that don't test class but fit the same
criterea- like #isUppercase- are still called as they should be, because
it never makes it to DNU.
The changes to DNU like this causes it to be quite a bit slower, but the
net result that'd have to the whole system I do not know. It might just be
a goony idea- no reason one can't just call #isKindOf:, although it is a
bit more inconvenient, and can lead to using parentheses. :)
I did a little prototype of this, which I attached my own subclass of
Morph (just picked it, no real reason to be a Morph) and it worked pretty
well.
"-----------------------------------------------------------------------"
doesNotUnderstand: aMessage
| selector |
selector _ aMessage selector.
(selector beginsWith: #is)
ifFalse: [^ super doesNotUnderstand: aMessage].
(selector third isUppercase
and: [selector numArgs == 0])
ifTrue: [^ self isKindOf: (Smalltalk
at: (selector allButFirst: 2) asSymbol
ifAbsent: [^ super doesNotUnderstand:
aMessage])].
^ super doesNotUnderstand: aMessage
"-----------------------------------------------------------------------"
Regards,
Aaron
--
"civilization is a limitless multiplication of
unnecessary necessities." :: mark twain
More information about the Squeak-dev
mailing list
|