From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada Annoyances Date: Thu, 22 Jun 2017 23:52:40 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <1ac5a44b-4423-443a-a7bb-2864d9abe78f@googlegroups.com> <1498048151.20885.28.camel@obry.net> <96174ea5-852d-44e9-8535-7c1eb24d5326@googlegroups.com> <98b98b8b-2f56-4d14-9989-3df51b08d97e@googlegroups.com> NNTP-Posting-Host: MajGvm9MbNtGBKE7r8NgYA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:47062 Date: 2017-06-22T23:52:40+02:00 List-Id: On 2017-06-22 21:22, Niklas Holsti wrote: > On 17-06-22 16:30 , Dmitry A. Kazakov wrote: >> On 22/06/2017 12:29, pythoner6@gmail.com wrote: >> >>> What do you mean by "re-dispatch" here? How is it different from the >>> dynamic dispatch that happens in Ada with class-wide types? >> >> Re-dispatch is dynamic dispatch when you go through the same virtual >> table twice. > > I think that is inaccurate, unless you have a different definition of > "re-dispatch" from what I remember of discussions re this topic. > > Consider: > > type Parent is tagged record .... end record; > > procedure Foo (P : Parent); > procedure Bar (P : Parent); > > type Child is new Parent with record ... end record; > > -- Child inherits Foo from Parent. > > overriding procedure Bar (C : Child); > > followed by > > C : Child; > > Foo (C); > > That call is not dispatching, so it does not go through the "virtual > table". It calls the inherited Foo for Child. > > Now suppose Foo (P : Parent) does a (re-) dispatching call to Bar, which > in this example calls the overriding Bar (C : Child): > > procedure Foo (P : Parent) > is > begin > Bar (Parent'Class (P)); > end Foo; > > I believe this call of Bar is considered "re-dispatching", because there > is a conversion from Parent to Parent'Class (effectively, Child). But > there is only one use of the "virtual table". It is not good either for similar reasons of type violation. But I would not call it re-dispatch. There is many ways to achieve the same [wrong] effect. E.g. without any dispatch: procedure Foo (P : Parent) is begin Bar (Some_Descendant_Of_Parent (P)); end Foo; > As you have often said. I still disagree. Just to let the OP know > that opinions differ on this topic. Yes, to elaborate a bit on the issue. The problem is that the contract of Foo tells that P is of the type Parent and of nothing else. So any operations applied to P must of the same type. If there must be other types the contract must say so. E.g. Parent'Class or some narrower class. Unfortunately there is no way to express anything in between Parent and Parent'Class. But that is a different story. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de