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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.36.118.21 with SMTP id z21mr16244761itb.18.1511806255762; Mon, 27 Nov 2017 10:10:55 -0800 (PST) X-Received: by 10.157.33.82 with SMTP id l18mr1694231otd.6.1511806255682; Mon, 27 Nov 2017 10:10:55 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!i6no7604389itb.0!news-out.google.com!193ni4760iti.0!nntp.google.com!193no1196889itr.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 27 Nov 2017 10:10:55 -0800 (PST) In-Reply-To: <6106dfe6-c614-4fc1-aace-74bf8d7435e3@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=155.148.6.150; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 155.148.6.150 References: <4db43571-7f86-4e73-8849-c41160927703@googlegroups.com> <6496a10f-c97e-4e42-b295-2478ad464b2f@googlegroups.com> <6106dfe6-c614-4fc1-aace-74bf8d7435e3@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <24767ee5-cda8-45e4-98d1-7da44757bd40@googlegroups.com> Subject: Re: Extending a third party tagged type while adding finalization From: Shark8 Injection-Date: Mon, 27 Nov 2017 18:10:55 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 3652 X-Received-Body-CRC: 1022935447 Xref: reader02.eternal-september.org comp.lang.ada:49191 Date: 2017-11-27T10:10:55-08:00 List-Id: On Sunday, November 26, 2017 at 10:33:50 AM UTC-7, Jere wrote: > > What I tried to do was use a mixin but have it keep a reference to a > classwide access on the object. Then I tried dispatching out to the > correct object type from there. This kind of highlighted the evils > of using redispatch in Ada though as I found that if I had component > definitions like this: JP Rosen's paper "A Naming Convention for Classes in Ada 9X" details a way you might be able to ease the pain of such constructs. The example of adding a "with benefits" extension to "computer scientist" which is itself an "employee" is detailed as follows: with Employee; use Employee; generic type Origin is new Employee.lnstance with private; packaqe With_Benefits_Facet is type Instance is new Origin with private; subtype Class is Instance'Class; -- Operations to handle benefits private end With__Benefits_Facet; -------------------------------- with Computer__Scientist, With_Benefits_Facet; use Computer_Scientist; package Computer_Scientists__With__Benefits is new With__Benefits__Facet(Computer_Scientist. Instance); So, to do this sort of thing how you want, couldn't you handle things via generic? Generic -- You might want to put a Base here and derive from it... Type Controlled is limited private; with procedure Initialize (Object : in out Controlled) is null; with procedure Adjust (Object : in out Controlled) is null; with procedure Finalize (Object : in out Controlled) is null; Package Controlled_Mixin is Type Instance is new Ada.Finalization.Limited_Controlled with record Component : Controlled; end record; --... End Controlled_Mixin; > > Based on what I have read so far, I didn't see any discussion that would > lead me to think this will be changed at least in the near future. I > wish there was a way it would be easy for vendors to do something like: > > type Some_Type is tagged private; > for Some_Type'Initialize use Initialize_Some_Type; > for Some_Type'Adjust use Adjust_Some_Type; > for Some_Type'Finalize use Finalize_Some_Type; > > and then just have the compiler handle adding the needed structures > to the type under the hood (like how GNAT uses Controlled to hold > a linked list under the hood...but compiler managed). That would be pretty nice.