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.0 required=3.0 tests=BAYES_40,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:ac8:44aa:: with SMTP id a10mr1732085qto.116.1599107416453; Wed, 02 Sep 2020 21:30:16 -0700 (PDT) X-Received: by 2002:ae9:c208:: with SMTP id j8mr1355213qkg.279.1599107416336; Wed, 02 Sep 2020 21:30:16 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 2 Sep 2020 21:30:16 -0700 (PDT) In-Reply-To: <94a54092-a56f-4a99-aaec-08dd611c8fd8@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=122.179.156.234; posting-account=Wq4TXwoAAAA5THLfPXOBP-1Cg1k7sq35 NNTP-Posting-Host: 122.179.156.234 References: <94a54092-a56f-4a99-aaec-08dd611c8fd8@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0f9ee062-a96b-42c6-aff9-8c667d66038ao@googlegroups.com> Subject: Re: Proposal: Auto-allocation of Indefinite Objects From: linda white Injection-Date: Thu, 03 Sep 2020 04:30:16 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:59932 List-Id: On Saturday, 4 April 2020 04:18:43 UTC+5:30, Stephen Davies wrote: > Firstly, apologies if this has already been discussed or, > more likely, if it's a really stupid idea for some reason > that I haven't thought of. > > My proposal is that it should (sometimes?) be possible to declare > objects of indefinite types such as String and have the compiler > automatically declare the space for them without the programmer > having to resort to access types. > > Benefits: > > 1. Easier, especially for newbies/students. > 2. Safer due to reduced use of access types. > 3. Remove the need to have definite and indefinite verions of generic units. > > It is the 3rd reason that initially got me thinking about this. > It seems excessive to have two versions of packages just because > one version can say "Node.Item := New_Item;" but the other has to say > "Node.Item_Ptr := new Element_Type'(New_Item);". > > It's probably not a good idea for auto-allocation to be the default > behaviour, so I suggest something like: > > type Node_Type is record > Item : new Element_Type; > Prev : Node_Ptr_Type; > Next : Node_Ptr_Type; > end record; > > If Element_Type is a definite type in the instantiation then > Node.Item will be a normal object of that type. Otherwise, it is > implemented as a pointer but the code still treats it as an object. > The target of the pointer is allocated on assignment of the object. > The pointer cannot be copied to any other object. Assignments of the > whole record will perform a deep-copy of the auto-allocated component. > The target of the Node.Item pointer can be auto-deallocated when Node > goes out of scope or is deallocated. > > Ok, I've probably missed something obvious and have been wasting my > time, but at least I've got plenty of time to waste at the moment.