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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,4ce5890331a5b529 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!takemy.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Discriminants of tagged types Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <14314714-e92c-4036-9cbb-da8e72489261@h7g2000yqn.googlegroups.com> <1bytu43t5bi8y.1t3tebqbls31j.dlg@40tude.net> Date: Wed, 27 Oct 2010 16:12:42 +0200 Message-ID: NNTP-Posting-Date: 27 Oct 2010 16:12:42 CEST NNTP-Posting-Host: be586daf.newsspool2.arcor-online.net X-Trace: DXC=NifJ97ce]@RE47KDAk81NWA9EHlD;3YcR4Fo<]lROoRQ8kF On Wed, 27 Oct 2010 09:52:48 -0400, Robert A Duff wrote: > "Dmitry A. Kazakov" writes: > >> On Wed, 27 Oct 2010 05:34:26 -0700 (PDT), Ludovic Brenta wrote: >> >>> The tag has no default value and cannot have one, for that would >>> allow changing the type of an object at run time (through assignment >>> of an aggregate). >> >> No, it would not because you cannot assign a value of another type. > > I think Ludovic means that the Tag could change. That is, tags > are sort of like discriminants, so if Tags could have defaults, > then we can guess that they would inherit the strange rule "can change > if defaulted". So this would work: > > A : T1; > B : T'Class := A; > C : T2; > > B := C; -- Raises an exception. But this is an unrelated case. The tag of a specific type cannot be changed regardless its view as a discriminant. Considering the class-wide type, its discriminants are unknown, it is an open set. So the standard rules here do not apply anyway. BTW, if we considered class-wide assigment dispatchng, we would come to the case of a specific type when the tags are same, or to Constraint_Error when they differ. And independently on defaults: A : T1; B : T2; C : T'Class := A; D : T'Class := B; C := D; >>> Therefore, *additional* discriminants cannot have default values either. >> >> I think there were concerns about implementation difficulties when the >> derived type adds new discriminants and/or defines some inherited ones. >> >> Anyway the limitation is indeed annoying. > > Then you won't like my opinion, which is that this feature should > never have existed even for untagged types. It's useful, but > it's just not worth the trouble, in terms of programmer confusion, > and implementation difficulty. Also nonportability: > > type T(Length: Natural := 0) is > record > S: String(1..Length); > end record; > > This works on some implementations, and not others. It might wonder you, but I wholeheartedly agree with you, but for another reason. The problem default values are supposed to solve IMO, should be solved by constructors and user-defined aggregates. If they existed and for any type, the programmer could provide variable list of arguments passed to the constructor. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de