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!feeder.eternal-september.org!news.unit0.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Variant record with multiple discriminants? Date: Sat, 28 Oct 2017 21:47:33 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 4YdxaQeyGfRpufClpdL14QWRCsTNfHlXpcBXb/Xs9PbHp6ZN5k Cancel-Lock: sha1:0YAe18WeajtIlVJxl5SOjCabCz0= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:48616 Date: 2017-10-28T21:47:33+03:00 List-Id: On 17-10-28 20:05 , Victor Porton wrote: > Ada does not support variant records whose fields presence depends on > multiple discriminants, does it? Yes it does, in two ways: - a component in a variant (RM 3.8.1) can itself be of a discriminated record type, and can take the actual value of its discriminant from some discriminant of the containing record - the component_list in a variant can contain nested variant_parts, that is, the "case .. when .. when .. end case" structure can be nested. Example: type Int_Or_Char_T (Is_Int : Boolean) is record case Is_Int is when True => I : Integer; when False => C : Character; end case; end record; type Float_Or_Int_Or_Char_1_T (Is_Float : Boolean; Is_Int : Boolean) is record case Is_Float is when True => F : Float; when False => IC : Int_Or_Char_T (Is_Int); end case; end record; type Float_Or_Int_Or_Char_2_T (Is_Float : Boolean; Is_Int : Boolean) is record case Is_Float is when True => F : Float; when False => case Is_Int is when True => I : Integer; when False => C : Character; end case; end case; end record; The main limitation is that the values used in the "case" constructs, or supplied as actual discriminant values for sub-records, must be discriminants of the parent record, and cannot be computed expressions. For example, it would be illegal to declare the "IC" component in this way, using a Boolean expression as the discriminant value: when False => IC : Int_Or_Char_T (not Is_Int); -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .