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-Thread: 103376,195f9d06474696b0,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!news.banetele.no!news.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Choice of variant record discriminant (design question) Date: Wed, 26 Oct 2005 14:21:53 +0200 Organization: Jacob's private Usenet server Message-ID: NNTP-Posting-Host: hugin.crs4.it Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: jacob-sparre.dk 1130329314 2823 156.148.71.67 (26 Oct 2005 12:21:54 GMT) X-Complaints-To: sparre@jacob-sparre.dk NNTP-Posting-Date: Wed, 26 Oct 2005 12:21:54 +0000 (UTC) User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:NO0Bq65CKhEVNR10x19sVU9IXFM= Xref: g2news1.google.com comp.lang.ada:5954 Date: 2005-10-26T14:21:53+02:00 List-Id: I have declared a record type like this: type Preprocessed_Parameters (Measurement_Count : Natural := 0) is record case Measurement_Count is when 0 => null; when others => Mean_Value : Scalar; Scaled_Variance : Scalar; end case; end record; I would like to return an object of that type from a function using this piece of code: if Count = 0 then return (Measurement_Count => 0); else [...] return (Measurement_Count => Count, Mean_Value => Mean, Scaled_Variance => Sum); end if; I can't do this, since the discriminant has to be static. The obvious solution to the problem is to change the record declaration into: type Preprocessed_Parameters (Empty : Boolean := True) is record case Empty is when True => null; when False => Measurement_Count : Positive; Mean_Value : Scalar; Scaled_Variance : Scalar; end case; end record; but I have a feeling there ought to be a more elegant solution. Does somebody have a suggestion or two? Jacob -- ACRONYM: A Contrived Reduction Of Nomenclature Yielding Mnemonics