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

Re: simple method dispatch question



Rob Myers wrote:
...
> define method maybe-works( obj :: <test2> )
>     maybe-works( as( <test1>, obj ) );
>     maybe-works( as( <test>, obj ) );
..
> work? Assuming test1 and test are superclasses of test2, won't obj just get
> cast down? Or is this C++ rather than Dylan? :-)

  It is C++.   There is no "cast" in Dylan.  An object is what it is. 
  Objects have identity; not multiple personality disorder. :-)
   This might work. But you'd get two new objects ( assuming <test1> and
  <test> are directly instantiable).  Otherwise you might end up
  with one or two more <test2> objects or perhaps the same <test2> object. 
 
  "as" is more of an instance creator than a mechanism of pretending
  you have a different direct type of object. It is legal for 
  "as" for directly return the object argument, but that's because
  the argument was the proper concrete instance for the type you asked 
  for. 

  Actually, if I recall correctly, it might not work in C++ either. 
  Given that to be approximately equivalent, obj would be a pointer 
  and maybe-works would be a virtual function. 

  
Lyman



References: