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,e8550e5b10c2c0 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-28 18:34:23 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!feed.newsfeeds.com!cyclone-sf.pbi.net!151.164.30.35!cyclone.swbell.net!newsfeed1.easynews.com!easynews.com!easynews!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3E601C1A.3000405@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Variant Record Component References: <3E5D00D6.F6A20AD2@boeing.com> <3E5F8B38.EE7AE76F@boeing.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 01 Mar 2003 02:34:28 GMT NNTP-Posting-Host: 63.184.17.248 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1046486068 63.184.17.248 (Fri, 28 Feb 2003 18:34:28 PST) NNTP-Posting-Date: Fri, 28 Feb 2003 18:34:28 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:34751 Date: 2003-03-01T02:34:28+00:00 List-Id: John Harbaugh wrote: > > My question has more to do with understanding what language-level tools > that are available. Ada is pretty slick at testing membership of a > value within/without a subtype range. I was wondering if there was > something analogous for variant records. I'm getting the impression > that the answer is no. Yes? No. Subtype membership is defined for all types. For a variant record type, you can say type Disc is (Alpha, Bravo, Charlie); type Variant (D : Disc) is record case D is when Alpha => ... ... end case; end record; subtype Variant_Alpha is Variant (D => Alpha); V : Variant := Some_Function; ... if V in Variant_Alpha then This will work if you've done a good design, and each Disc value has its own variant part. If most of the variant parts have multiple discriminant values then this is less useful. I once saw a project (Ada 83, pre 1995) that had problems because they'd done something like type Disc is range 1 .. 100; type Variant (D : Disc) is record case D is when 1 .. 10 => ... when 11 .. 20 => ... ... end case; end record; What they really had was a set of about 10 main classes, each of which had a specific ID for one of about 10 specific things. What they should have done was something like type Disc is (One, Two, ..., Ten); type ID_One is (One_One, One_Two, ..., One_Ten); type ID_Two is (Two_One, Two_Two, ..., Two_Ten); ... type ID_Ten is (Ten_One, Ten_Two, ..., Ten_Ten); -- The project would have had more meaningful names, -- but since it was a classified project I can't tell -- you what they would have been. type Variant (D : Disc) is record case D is when One => One_ID : ID_One; ... when Two => Two_ID : ID_Two; ... ... end case; end record; -- Jeff Carter "C++ is like giving an AK-47 to a monk, shooting him full of crack and letting him loose in a mall and expecting him to balance your checking account 'when he has the time.'" Drew Olbrich