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-05 07:59:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!worldnet.att.net!199.45.49.37!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> <3EDE998D.3060701@attbi.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: Thu, 05 Jun 2003 14:59:04 GMT NNTP-Posting-Host: 151.203.234.174 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny02.gnilink.net 1054825144 151.203.234.174 (Thu, 05 Jun 2003 10:59:04 EDT) NNTP-Posting-Date: Thu, 05 Jun 2003 10:59:04 EDT Xref: archiver1.google.com comp.lang.ada:38682 Date: 2003-06-05T14:59:04+00:00 List-Id: "Robert I. Eachus" wrote in message news:3EDE998D.3060701@attbi.com... > I like the idea, but there are some practical problems. First, a > property of arrays in Ada, is that several attributes are currently > predefined. For Foo(Foo'First) to work correctly, you need user defined > attributes. Fortunately, the syntax is already "in there," but the > attributes that can be defined would have to be extended, and there > would probably be a rule required that when you defined an "()" > function, the 'First, 'Last, 'Length, and 'Range attributes would become > abstract and need to be overridden befor you could use the type. In other words, why not allow the programmer to specify, in a standard fashion, an iteration sheme (similar to the C++ iterators) for visiting each index in a container object? Ada already has a lot of the intrasturcture there, with the 'First, 'Last, 'Succ and 'Pred attributes. This idea has a lot of merit, and should be explored further. It would be very nice if Ada0x was designed so that a programmer could write for I in Foo'Range loop ... end loop; for a user-defined array-like type. > Also, I think that procedure "()" makes more sense, but that is just > nomenclature. What is not nomenclature is that Ada already allows > functions as prefixes on the left-hand side of assignment statements! > (The function has to return an access type, but from there on everything > works like you would expect.) So I recommend instead: > > -- Function used to evaluate Source( Index ) > function "()" ( Source : in Array_Like_Type; > Index : in Index_Type ) > return Component_Type; > > for Source'First use My_First; > for Source'Last use My_Last; > -- I think that allowing a definition of 'Range other than > -- Source'First..Source'Last would require too much invention. > -- Given that, Source'Length can be defined as > -- Index_Type'Pos(Source'Last) - Index_Type'Pos(Source'First) + 1. > > -- function for assigning Value to Source( Index ) > function "()" ( Source : in out Array_Like_Type; > Index : in Index_Type) > return Component_Type'Access; > > Yes, that does though have the effect that for some types with packed > representations you are not going to be able to define the second > operation, so you must still use a procedure call to do the > modification. But it should work fine for sparse array implementations. Granted, the function returning Component_Type'Access would work in many cases, but I still think that the most general and powerful approach is to have the "()" function and "():=" procedure. Consider an instantiation of Ada.Direct_Io: type Element_Type is record ... end record; package Element_Io is new Ada.Direct_Io( Element_Type ); use Element_Io; My_File : Element_Io.File_Type; An open file of type Element_Io.File_Type can be thought of as an array of objects of type Element_Type. In fact, one could view such a file as an array of Element_Type objects that are stored in a random access file instead of memory. Given this view, why not use array notation for the handling the contents of this file? With the "()" and "():=" operators, we could extend Ada.Direct_Io so that Read( File => My_File, Item => My_Element, From => Index ); could also be written (using the "()" function) as My_Element := My_File( Index ); Conversely, the "():=" procedure can be used to write to the file, i.e. instead of writing Write( File => My_File, Item => My_Element, To => Index ); the programmer would be able to write My_File( Index ) := My_Element;