comp.lang.ada
 help / color / mirror / Atom feed
From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov)
Subject: Re: Merits of re-dispatching [LONG]
Date: Mon, 18 Feb 2002 08:57:11 GMT
Date: 2002-02-18T08:57:11+00:00	[thread overview]
Message-ID: <3c70b935.501062@News.CIS.DFN.DE> (raw)
In-Reply-To: memo.20020216121052.11581C@brangdon.madasafish.com

On Sat, 16 Feb 2002 12:10 +0000 (GMT Standard Time),
brangdon@cix.co.uk (Dave Harris) wrote:

>dmitry@elros.cbb-automation.de (Dmitry A. Kazakov) wrote (abridged):
>> That there are three types changes nothing. It works pretty well in
>> Ada 95:
>
>That still doesn't capture the full complexity, because although you have 
>Foo you don't have a Call_Foo. The call to Foo from within Call_Foo must 
>be dispatching, because it must dispatch to different places. Given that 
>it can do this, it's simplest to say the call to Foo from within the 
>destructor is dispatching too, in the same way. So there is no 
>non-dispatching call in the C++.
>
>I don't know Ada, but I think it would look like:
>
> type A is ...
> procedure Foo (Object : A) is
> begin
>    Put_Line ("A.Foo");
> end Foo;
> procedure Call_Foo (Object : A) is
> begin
>    Foo( Object );  -- Dispatching, A.Foo or B.Foo called.

One correction, it should be:

Foo (A'Class (Object)); -- Re-dispatch to "native" Foo

> end Foo;
> procedure Finalize (Object : in out A) is
> begin
>    Call_Foo (Object);
>    Foo (Object);
> end Finalize;
>
> type B is new A ...
> procedure Foo (Object : B) is
> begin
>    Put_Line ("B.Foo");
> end Foo;
> procedure Finalize (Object : in out B) is
> begin
>    Call_Foo (Object); 
>    Foo( Object );
>    Finalize (A (Object));
> end Finalize;
>
>This should produce B.Foo B.Foo A.Foo A.Foo.

With my correction it will produce:

B.Foo B.Foo B.Foo A.Foo.
 \         \        \         \
  \         \        \         Foo from A.Finalize -> A.Foo
    \         \       Call_Foo form A.Finalize -> B.Foo (dispatch)
     \        Foo from B.Finalize -> B.Foo
       Call_Foo form B.Finalize -> B.Foo (dispatch)

Alternatively, you could make Call_Foo class wide:

procedure Call_Foo (Object : A'Class) is
begin
    Foo (Object);  -- Dispatching
end Call_Foo;

This is the official way to say that we want to dispatch on A from it
and thus it is defined for all A derivates. [=>it cannot be
overridden] Then a call to Call_Foo form B.Finalize could look as
follows:

   Call_Foo (A'Class (Object)); -- Prepare Object to re-dispatching

The result output will be same. [Ada is a consistent language (:-))]

>The call to Foo from B.Finalize can use exactly the same implementation
>as the call to Foo from A.Call_Foo.

If both are dispatching, but they are not. Only the call from Call_Foo
is dispatching.

>Both end up in B.Foo when the object is of type B. Both are 
>dispatching calls.

That's the point. Why on earth a call to Foo from B.Finalize should
dispatch? The type is known, so there is only one version of Foo to be
called. It can be resolved at compile time and even inlined if
necessary. In Ada it does not dispatch. And that is good. But my point
was that additionally to that there must be no way to enforce
dispatching [like in Call_Foo], because it is unsafe and inefficient.

Regards,
Dmitry Kazakov



  reply	other threads:[~2002-02-18  8:57 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-07 10:26 Merits of re-dispatching [LONG] Dmitry A. Kazakov
2002-02-07 15:03 ` Hyman Rosen
2002-02-08  1:29   ` Matthew Heaney
2002-02-08  9:16     ` Dmitry A. Kazakov
2002-02-08 18:30       ` Hyman Rosen
2002-02-09  0:10         ` Matthew Heaney
2002-02-12  8:32         ` Dmitry A. Kazakov
2002-02-12 21:37           ` Hyman Rosen
2002-02-13  9:29             ` Dmitry A. Kazakov
2002-02-13 14:32               ` Hyman Rosen
2002-02-13 19:58           ` Dave Harris
2002-02-14 15:06             ` Dmitry A. Kazakov
2002-02-16 12:10               ` Dave Harris
2002-02-18  8:57                 ` Dmitry A. Kazakov [this message]
2002-02-18 19:47                   ` Merits of re-dispatching Dave Harris
2002-02-19  9:20                     ` Dmitry A. Kazakov
2002-02-21  5:49                       ` Hyman Rosen
2002-02-21  9:04                         ` Dmitry A. Kazakov
2002-02-21 18:17                           ` Hyman Rosen
2002-02-22  9:21                             ` Dmitry A. Kazakov
2002-02-22 16:59                               ` Hyman Rosen
2002-02-25  8:51                                 ` Dmitry A. Kazakov
2002-02-08 23:51       ` Merits of re-dispatching [LONG] Matthew Heaney
2002-02-12  9:02         ` Dmitry A. Kazakov
2002-02-07 23:40 ` Nick Roberts
2002-02-08  8:56   ` Dmitry A. Kazakov
2002-02-08  1:06 ` Matthew Heaney
2002-02-08  9:48   ` Dmitry A. Kazakov
2002-02-09  0:16     ` Matthew Heaney
2002-02-08 18:10   ` Hyman Rosen
2002-02-09  0:41     ` Matthew Heaney
2002-02-08 18:33 ` Nick Roberts
2002-02-09  4:07   ` Nick Roberts
2002-02-12 10:13   ` Dmitry A. Kazakov
2002-02-14 20:57 ` Tucker Taft
2002-02-15 15:43   ` Dmitry A. Kazakov
replies disabled

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