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!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Strings with discriminated records Date: Sun, 27 May 2018 10:39:33 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <55ce14eb-6b83-4ea0-a550-f9e1410d0b06@googlegroups.com> <704ab1a8-c954-460e-81e7-05c64fcfaba4@googlegroups.com> NNTP-Posting-Host: CvkHMVp693S8Z+lk11jyqg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 X-Notice: Filtered by postfilter v. 0.8.3 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:52720 Date: 2018-05-27T10:39:33+02:00 List-Id: On 2018-05-27 03:42, NiGHTS wrote: > On Saturday, May 26, 2018 at 7:42:22 PM UTC-4, Shark8 wrote: >> You can do this: >> >> Type Message(Length : Positive) is record >> Text : String(1..Length); >> -- Other components. >> end record; > > More interesting to me would be to pass a string literal as a discriminant. Using your example, something like this... > > Type Message (Length : Positive; Text_Value : String) is record > Text : String(1..Length) := Text_Value; > -- Other components. > end record; > > This gives me an error: Discriminants must must have a discrete or access type There is no constructors and no user-defined aggregates, which you are actually asking for, but sometimes a constructing function does the job: function Create (Value : String) return Message is begin return (Length => Value'Length, Text => Value); end Create; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de