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: 103376,dad94612ff745427 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!fu-berlin.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Instantiating private types with discriminants? 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: Date: Tue, 9 May 2006 18:01:09 +0200 Message-ID: NNTP-Posting-Date: 09 May 2006 18:00:57 MEST NNTP-Posting-Host: bbd86641.newsread2.arcor-online.net X-Trace: DXC=8LdE5P7]NYBC;_l<5e4khAQ5U85hF6f;DjW\KbG]kaMH[NGU2GAcMGJfn`O1iBMRjNWRXZ37ga[7JjTA67ckJ=XE[G\7LRj5O5E X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4161 Date: 2006-05-09T18:00:57+02:00 List-Id: On Tue, 09 May 2006 14:48:44 GMT, rick H wrote: > Thank you, Georg, Ludovic and Dmitri for your replies. > > Now I know I won't get shouted at for asking novice questions, I have > another query for you experts, if you've got the time to have a look: > > I'm trying to query the tag of a record, which I can do quite nicely, > provided I both "with Ada.Tags" and "use Ada.Tags". Just for the sake > of it, I tried to remove the "use Ada.Tags" statement, but I can't work > out how I would then specify the XXX'Tag attribute of a variable. > Here's an example that illustrates my problem ("if Var_A'Tag..." is the > problem line): > > with Ada.Integer_Text_IO; > with Ada.Float_Text_IO; > with Ada.Tags; > -- use Ada.Tags; > > procedure Simple_Case is > type General_T is tagged null record; > > type Access_T is access General_T'Class; > > > type Type_A is new General_T with > record > Data : Integer; > end record; > > > type Type_B is new General_T with > record > Data : Float; > end record; > > > Var_A : Access_T; -- could be "new Type_A" or a "new Type_B" > begin > -- Var_A := new Type_A' (Data => 100); > Var_A := new Type_B' (Data => 100.0); > > -- problem line: > if Var_A'Tag = Type_A'Tag then > Ada.Integer_Text_IO.Put ( Type_A (Var_A.all).Data); > elsif Var_A'Tag = Type_B'Tag then > Ada.Float_Text_IO.Put ( Type_B (Var_A.all).Data); > end if; > end Simple_Case; You can do: if Var_A.all in Type_A then which is cleaner, and requires no reference to tags. BTW, You should probably make Put a primitive operation of General_T. Then the whole could look like simply: Put (Var_A.all); -- Do what have to be done -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de