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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1e0472f55fc12a52 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-20 01:15:55 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: How do I create an object instance from a tag? Date: Thu, 20 Feb 2003 10:15:53 +0100 Message-ID: References: NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1045732553 51515122 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:34259 Date: 2003-02-20T10:15:53+01:00 List-Id: On Wed, 19 Feb 2003 12:36:25 -0600, "Randy Brukardt" wrote: >"Grein, Christoph" wrote: >> >>So there are good reasons why there is not yet a solution for this >problem. > >The main one is discriminants. Tagged type discriminants never have >defaults. Moreover, you can add discriminants to any extension of a >tagged type, so you never can know if you have any. And, certainly, the >creation of an object with uninitialized discriminants is a no-no. [ I think we have already discussed this. A full solution is IMO only possible with proper constructors. ] As for uninialized discriminants, compare: type X (I : Positive) is record ...; A : X; -- Illegal B : X := (I => 10, ...); -- OK How does it differ from: A : X'Class (A_Tag); -- Raises an exception when A_Tag refers to an unconstrained type A : X'Class (A_Tag) := Make_X; -- Dispatches to Make_X, which provides all constraints The only diference is that the latter is not compile-time checkable. However this can be solved. For example, one could define two different tag types: one for all types another for constrained types only [with appropriate conversion functions between them]. Then with a general tag, T'Class(Tag) would counted as unconstrained, and thus illegal without an initialization. With a "constrained" tag T'Class(Tag) would be OK. >What you really want to do is force the calling of a particular >constructor function. (That's what T'Class'Input does, after all, with >T'Input being the constructor). > >If you have a dispatching constructor "Make", then you want something >like: > > Obj : T'Class := T.Make () using ; > >But the reviewers thought that special syntax was overkill for this >problem, and no one has been able to come up with any other solution >that really works. Special syntax is bad here, because there is nothing special in dispatching on the result. There is everything for that. IMO the actual problem is an unability to specifiy the type of the target object. Solve this, and the rest will come for free. IMHO tag should be viewed as a constraint (discriminant) for T'Class. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de