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!.POSTED!not-for-mail From: "Alejandro R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: 'Class'Class'Class'Class ad libitum Date: Tue, 13 Sep 2016 18:54:24 +0200 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 13 Sep 2016 16:54:21 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="bc686c1890d5fda24d69bb608fea27b4"; logging-data="21275"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ajU8eO+9zLnDMTMW5poE7" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: Cancel-Lock: sha1:tb6bX+f4ZZHZ9kl027boD5Eb7dM= Xref: news.eternal-september.org comp.lang.ada:31776 Date: 2016-09-13T18:54:24+02:00 List-Id: On 13/09/16 18:34, Dmitry A. Kazakov wrote: > On 2016-09-13 18:10, Alejandro R. Mosteo wrote: >> On 13/09/16 14:37, Dmitry A. Kazakov wrote: >>> On 13/09/2016 12:43, Alejandro R. Mosteo wrote: >>>> I get why this is legal: >>>> >>>> type X is tagged null record; >>>> >>>> subtype Y is X'Class; >>>> >>>> subtype Z is X'Class'Class'Class'Class; >>>> >>>> But can you think of any legitimate reason to use it besides >>>> obfuscation? >>> >>> Only the latter is wrong. X'Class'Class cannot be same as X'Class. >>> >>> X is a set of values with operations on X >>> >>> X'Class is a set of values of X and values of all types derived from X >>> >>> X'Class'Class should be a set of values of X'Class and values of all >>> types derived from X'Class. We cannot derive from X'Class in Ada, so >>> class of X'Class holds only X'Class. But that does not make them same. >>> Like X is not same as X'Class even if there is no descendants of X. >>> Class-wide operations of X would be primitive operations of >>> X'Class'Class. >> >> I see that from a strict theoretic POV. However, that's not the >> interpretation that current Ada grammar does, right? > > Semantics you mean. That semantics is wrong. If T'Class'Class is legal, > I don't know. It should not be otherwise than in the described above sense. > >> Actually I arrived at this because I am somewhat wary of the fact that >> using a subtype like Y in my example hides the fact to the reader that >> the type is class-wide and hence dispatching by default. > > Dispatching is a property of an operation's argument, not of a type. The > same object may dispatch or not. It should not be reader's concern. > Dispatching is merely a method of operation implementation, that is by > composition of the operation body out of multiple bodies of other > operations selected by the tag. It is a pure implementation detail. True, but the reader/user needs to make explicit the class-wideness of a value if dispatching is desired (and conversely), and this can lead to errors. GPS nowadays highlights dispatching calls... > >> Furthermore, >> you can legally write >> >> procedure Blah (This : Other_Package.Y); -- or >> procedure Blah (This : Other_Package.Y'Class); >> >> and AFAIK that's totally equivalent but the former is less informative >> (and alas, shorter to write). > > From the original Ada POV the former is better. Initially Ada strove to > have nominal typing. T'Class notation parts with that, it is structural > equivalence, which is not that great. Interesting. > >> First time I wrote the later I expected to >> get an error or warning of the short "subtype is already class-wide". > > A good catch by compiler. That Gnat does not perform ;)