From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.2uCIJahv+a4XEBqttj5Vkw.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Proposal: Auto-allocation of Indefinite Objects Date: Sat, 1 Aug 2020 14:58:06 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <94a54092-a56f-4a99-aaec-08dd611c8fd8@googlegroups.com> NNTP-Posting-Host: 2uCIJahv+a4XEBqttj5Vkw.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:68.0) Gecko/20100101 Thunderbird/68.11.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:59622 List-Id: On 01/08/2020 13:22, Stephen Davies wrote: > On Friday, 31 July 2020 at 11:20:09 UTC+1, Dmitry A. Kazakov wrote: >> On 31/07/2020 11:25, Stephen Davies wrote: >>> On Friday, 3 April 2020 at 23:48:43 UTC+1, Stephen Davies wrote: >>> Perhaps a better way to think of this is as a discriminated record without >>> an explicit discriminant? In which case maybe a different syntax than "new" >>> would be appropriate? >> That is right, but it would be a much larger problem to resolve than >> your original proposal. >> First, Ada lacks necessary discriminants ... >> Second, Ada's object initialization process has no means to determine >> discriminants... >> Third, there is still the problem that task components do not work... >> All in one, the crude work-around has always been an access type... > > Maybe I'm missing something but my thought was maybe there is no > need for a named discriminant, e.g. > type Node_Type (<>) is record > Item : Element_Type; > Prev : Node_Ptr_Type; > Next : Node_Ptr_Type; > end record; > The rules for such records would be the same as for discriminated ones, > except that instead of usages needing to provide values for discriminants, > they would need to provide values for indefinite components. 1. There is no discriminants for cases when Item is T'Class. 2. You cannot get discriminant from the value in the case of Rosen trick. Consider Item being a task with the access to the actual node as its discriminant: type Node_Type; task type Worker (Node : not null access Node_Type) is ...; type Mode_Type is record Item : Worker (Node_Type'Unchecked_Access); Prev : Node_Ptr_Type; Next : Node_Ptr_Type; end record; You cannot initialize Item because you cannot construct Worker without having the node. And you cannot have the node without having Item initialized. 3. Copying is involved. There should be none, especially for limited types. Limited returns are broken per construction and nothing could ever fix them. ------------------------- If the only problem were to deduce discriminants from a value. We could leave Node_Type as-is and simply fix aggregates: type T (L : Natural) is record S : String (1..L); I : Integer; end record; Why not to make this legal? X : T := ("hello!", 123); -- L is deduced from S -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de