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 15:03:40 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <55ce14eb-6b83-4ea0-a550-f9e1410d0b06@googlegroups.com> <704ab1a8-c954-460e-81e7-05c64fcfaba4@googlegroups.com> <3b84f73c-c752-4258-9e75-7f53f4f3b5cf@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 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.3 Xref: reader02.eternal-september.org comp.lang.ada:52725 Date: 2018-05-27T15:03:40+02:00 List-Id: On 2018-05-27 14:48, Mehdi Saada wrote: >> Type Message (Length : Positive; Text_Value : String) is record >> Text : String(1..Length) := Text_Value; >> -- Other components. >> end record; > The only interest in this would be being able to omit Length, and have the compiler write text: string (text_value'range) := text_value; > But it's a pretty limited improvement... not worth the work. > But type AA (LL : access String) is record > L : String := LL.all; > end record; > should be allowed, I guess, for the same reason as in my other post. Access discriminant is not intended for initialization. Initialization must be done by a constructor or a user-defined aggregate instead of misusing disciminants for this purpose. The reason why access discriminant is not allowed for non-limited types is assignment. Consider this: function Mess return AA is Local : aliased String := "Catch me if you can"; Result : AA (Local'Access); begin return Result; end Mess; Then Mess.LL.all; -- Oops! -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de