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 15:30:12 +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: vZYCW951TbFitc4GdEwQJg.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 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 X-Notice: Filtered by postfilter v. 0.8.2 Content-Language: en-US Xref: news.eternal-september.org comp.lang.ada:47057 Date: 2017-06-22T15:30:12+02:00 List-Id: 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. Since you are already there = you have determined the actual specific type, it does not make sense (and dangerous) to do this again. (I know that there are software patterns based on re-dispatch, they all are wrong.) >> It is controlled by the type, because see above, Ada is properly typed. >> The dispatch never happens on a tagged type T. It always do on a >> class-wide type T'Class, which is not tagged. T /= T'Class. > > Yes, this is exactly this (rather crucial) distinction I didn't > really understand. Part of it I think was that the word class didn't have the > right associations in my mind, coming from C++ where a class is just one > kind of type. A class rooted in the type T (T'Class) is a new type with values corresponding to the values of T and the values of all types derived from T. The idea of class is to have an object that may hold any value of T or of any of its descendants. Trivially as a type T'Class cannot be T. It has a different set values. > In Ada it seems that class refers to a type and it's > descendants, e.g. a class of types. It is important to see the difference. There is a class T as a set of types derived from T. That is not a type, because it is a set of types. Then there is a proper type with values corresponding to the closure of the values of the types from that set. That is the class type (a class-wide type in Ada terms). class T is a set T'Class is a type (to mimic the closure of class T) A value of T'Class has in Ada as in C++ the same representation as the value of some derived type S from the set class T. This allows conversion forth and back between T'Class and S. In Ada terms this is called "view conversion". In C++ it is simply there. Confusion between T'Class and T prevents from having classes of scalar types with class-wide objects supporting dynamic dispatch. Ada does not have this either, but there is nothing that would prevent it to have them. In that case Integer'Class object would have different representation from Integer because we don't want to keep tag or vptr inside Integer. We would put that into Integer'Class and use proper type conversion instead of view conversion. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de