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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,70414f56d810c10c X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!1g2000yqm.googlegroups.com!not-for-mail From: AdaMagica Newsgroups: comp.lang.ada Subject: Re: discriminant questions Date: Tue, 20 Sep 2011 22:03:27 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5892818f-17c9-4349-add3-af40bd92c3d1@1g2000yqm.googlegroups.com> References: <9f37b726-d80b-4d24-bf3f-28a14255f7fd@s20g2000yql.googlegroups.com> <86015926-d652-4265-aedd-413312d399f9@dq7g2000vbb.googlegroups.com> <0d272f62-67d0-4905-972c-8a7e912c5531@en1g2000vbb.googlegroups.com> <148cxoyabima2.16mz6xwdph2hj.dlg@40tude.net> <1b7pl1piwc3hl.7q9fyyq8h3m7.dlg@40tude.net> <3d49749a-1da5-49b9-bc68-5d9befb4ed62@hb5g2000vbb.googlegroups.com> <1gti2q424e3tt$.18e95xse1r7j8$.dlg@40tude.net> <862244d4-c7ca-4590-ac97-e2988ac27872@f8g2000yqf.googlegroups.com> NNTP-Posting-Host: 80.156.44.178 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1316581848 10082 127.0.0.1 (21 Sep 2011 05:10:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 21 Sep 2011 05:10:48 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 1g2000yqm.googlegroups.com; posting-host=80.156.44.178; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESRCNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:22003 Date: 2011-09-20T22:03:27-07:00 List-Id: On 21 Sep., 01:28, ytomino wrote: > (To avoid confusion, I do not use names of "Get" and "Set".) > > function Element (C : Container) return Element_Type; > function Set_Element (C : Container; New_Item : Element_Type); > > These functions may copy Element_Type. > It's futile cost if Element_Type'Size is large. > > function Element (C : Container) return access constant Element_Type; > > It's dangerous. the reason is written in AdaCore Gem #107. > > procedure Query_Element (C : Container; Process : access procedure > (Item : in Element_Type)); > procedure Update_Element (C : Container; Process : access procedure > (Item : in out Element_Type)); > > These procedures are better than above functions. > No copy, no dangerous. > But, we must make nested subprogram, so source code may be verbosity. > > function Constant__Reference (C : Container) return > Constant_Reference_Type; > function Reference (C : Container) return Reference_Type; > > These functions give same effects as Query_Element and Update_Element. > And These are simple to use. > > In fact, Element, Set_Element, Query_Element and Update_Element are > able to be implemented with Reference. > The reverse is impossible. Nice synthesis. > Therefore I think Constant__Reference and Reference are more better > functions ... aside from primitive or not. > I also understand your feeling because the mechanism of accessor is > complex a little to call primitive. > But accessor is a nice idea, not kludge. And in Ada 2012, you write type Accessor (Data: access T) is limited private with Implicit_Dereference => Data; Get (P).Data.all := 42; -- is then equivalent to Get (P) := 42;