comp.lang.ada
 help / color / mirror / Atom feed
From: Ray Blaak <blaak@infomatch.com>
Subject: Re: Dynamic redispatching
Date: 2000/01/18
Date: 2000-01-18T00:00:00+00:00	[thread overview]
Message-ID: <m3hfgazg42.fsf@baka.infomatch.bc.ca> (raw)
In-Reply-To: 862gtg$meu$1@nnrp1.deja.com

Ted Dennison <dennison@telepath.com> writes:
> I'm trying to write a classwide function that dynamicly redispatches
> based on the tag of the function result. But it isn't dispatching on
> either of the two Ada compilers I tried. Here's an example:
[...]
>    function Main_Dispatcher return Class is
>    begin
>       return Dispatch;
>    end Main_Dispatcher;
[...]
> procedure Test is
>    Item : P1.Handle := new P2.Instance;
> begin
>    Item.all := P1.Main_Dispatcher;
> end Test;
> 
> When I run Test, of course I want it to dispatch to P2.Dispatch and
> return a value of type P2.Instance.

The problem is that you need an object to dispatch on. There is no information
inside Main_Dispatcher to decide which Dispatch to call, since by the time the
object is returned, it is too late (or more accurately, you are specifying only
to call P1.Dispatch).

In the statement "Item.all := P1.Main_Dispatcher", the contents of Item are
irrelevant, since only Main_Dispatcher can be called. Inside Main_Dispatcher,
no information about the result destination is known.

Perhaps this would work:

   Item.all := P1.Dispatch;

For then we have a function with a controlling result (I think), and it should
thus use the context (the tag of the destination) to dispatch.

I think the main problem was that Main_Dispatcher is not a primitive operation
of P1.Instance

-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
blaak@infomatch.com                            The Rhythm has my soul.




  reply	other threads:[~2000-01-18  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-18  0:00 Dynamic redispatching Ted Dennison
2000-01-18  0:00 ` Ray Blaak [this message]
2000-01-19  0:00   ` Ted Dennison
2000-01-20  0:00     ` Tucker Taft
2000-01-20  0:00       ` Ted Dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox