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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,73f15dbe4ec16d06 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-04 11:21:17 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!cyclone.bc.net!in.100proofnews.com!in.100proofnews.com!cycny01.gnilink.net!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny02.gnilink.net.POSTED!53ab2750!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: <1ec946d1.0306021542.58714996@posting.google.com> <1325634.ddflWlv0t0@linux1.krischik.com> <1ec946d1.0306040928.6eb47667@posting.google.com> Subject: Re: Adding "()" operator to Ada 200X X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: Date: Wed, 04 Jun 2003 18:21:16 GMT NNTP-Posting-Host: 151.203.234.174 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny02.gnilink.net 1054750876 151.203.234.174 (Wed, 04 Jun 2003 14:21:16 EDT) NNTP-Posting-Date: Wed, 04 Jun 2003 14:21:16 EDT Xref: archiver1.google.com comp.lang.ada:38634 Date: 2003-06-04T18:21:16+00:00 List-Id: "Matthew Heaney" wrote in message news:1ec946d1.0306040928.6eb47667@posting.google.com... > The problem is what type to return. In C++ I do this: > > T& operator[](); > const T& operator[]() const; > > The operator returns a reference to T. There are no reference types > in Ada, so it's not obvious how the language would be able to provide > it. I debated whether the right solution was to introduce some notion of reference types to Ada, so that the "()" functions would be declared something like this: function "()" ( Source : in Array_Like_Type; Index : in Index_Type ) return access Component_Type; This would parallel the C++ approach, and has worked very well in that realm. It occurred to me, however, that the reference type approach is assumes that in an object of a array-like type, each component is represented as an aliased section of memory of type Component_Type. One can easily think of many situations where this would not be the case: - the components might be stored in the array-like object in a packed format, so that they cannot be aliased; - the array-like object may be implemented using a file or database, so that the components are not in memory; - the components may be stored in some alternate representation; The reference type approach breaks down in these cases. As an alternative, I proposed separate "()" and "():=" for retrieving and assigning components in an array-like object. -- Function used to evaluate Source( Index ) function "()" ( Source : in Array_Like_Type; Index : in Index_Type ) return Component_Type; -- Procedure for assigning Value to Source( Index ) procedure "():=" ( Source : in out Array_Like_Type; Index : in Index_Type; Value : in Component_Type ); This approach makes very minimal assumptions about our array-like types: that we can retrieve a component from such an object given an index value, and that we can assign a component value at a given index. These assumptions would hold for virtually any type for which one would care to use the array notation. Moreover, the "()" and "():=" proposal does not require adding reference types to Ada.