[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic vs. static typing




On Nov 20, 2003, at 3:28 PM, Ken Shan wrote:
On 2003-11-19T02:22:49-0800, Steve Dekorte wrote:
 >> Can we have a type that declares that an object implements 
respondsTo:
 >> and *may* implement turnOff? If so, how does it prevent the 
possibility
 >> of a "does not respond to turnOff" error?
 >
 > One way to express what you said here, if I understand you correctly,
 > is to have respondsToTurnOff (a special case of respondsTo:) return a
 > certificate (understood by the type system) that the object will 
indeed
 > respond to turnOff.  The simplest such certificate is an object of the
 > type that does respond to turnOff -- the same object.

I don't find that an acceptable solution as it would be inconvenient in 
the extreme to have to implement a respondsToX for every possible X. If 
you're saying the existence of a generic respondsTo: method doesn't 
work in with ST, then I 'd say that's an example of how DT is more 
flexible and powerful.

To make sure there's no misunderstanding, here's a general Objective-C 
version of our method:

- makeRespondingPerform:(SEL)methodSelector
{
   id enm = [self objectEnumerator];
   id obj;
   while (obj = [enm next])
   {
     if ([obj respondsToSelector:methodSelector])
     {
       [obj performSelector:methodSelector];
     }
   }
   return self;
}

And the question is what type we should declare obj to be such that 
this would work and yet the program wouldn't potentially raise a 
runtime error if we removed the line:

if ([obj respondsToSelector:selector])

-- Steve