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 autolearn=ham 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 10:25:28 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: Adding "()" operator to Ada 200X Date: 5 Jun 2003 10:25:28 -0700 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0306050925.c16e3c3@posting.google.com> References: <1ec946d1.0306021542.58714996@posting.google.com> <1325634.ddflWlv0t0@linux1.krischik.com> <1ec946d1.0306040928.6eb47667@posting.google.com> <3EDE998D.3060701@attbi.com> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1054833928 30881 127.0.0.1 (5 Jun 2003 17:25:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 5 Jun 2003 17:25:28 GMT Xref: archiver1.google.com comp.lang.ada:38704 Date: 2003-06-05T17:25:28+00:00 List-Id: "Robert I. Eachus" wrote in message news:<3EDE998D.3060701@attbi.com>... > > 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: That's essentially why you don't really need this change in the language. I gave the example: To_Access (I).all := X; which does almost what you want. Instead of dereferencing a named iterator object, you could do this (ignoring the fact that Find can fail): To_Access (Find (Map, Key)).all := X; Of course, you could have Find return an access type directly: Find (Map, Key).all := X; No, this is not as simple as: Map [Key] := X; but it's pretty close. One thing I would like, in lieu of proper reference types, is to limit what a user is allowed to do with an access type, e.g. type Element_Access is limited access all Element_Type; or better yet type Element_Access (<>) is limited access all Element_Type; This would prevent the user from hanging on to the access object returned by Find. The C++ index operator can modify the map, to implicitly insert the key and construct the associated element with its default value; this allows you to do this (because scalars are initialized to 0): ++map[key]; To provide this feature in Ada you'll have to pass the map as an access parameter: Set (Map'Access, Key).all := X; This inserts the key into the map if it wasn't already in the map. To implement this using Charles, it's simple enough: function Set (Map : access Map_Subtype; Key : in Key_Subtype) return Element_Access is I : Iterator_Type; B : Boolean; begin Insert (Map.all, Key, I, B); return To_Access (I); end; Of course, if the map object is visible at the point of declaration of Set, then you can get rid of the map parameter, reducing the syntax to: Set (Key).all := X; http://home.earthlink.net/~matthewjheaney/charles/ I have a new release almost ready to go, containing new set and map containers that allow you to store elements that have a limited type. For example, this would allow you to create a set of files, with the file name as the key: package File_Sets is new Charles.Sets.Sorted.Limited_Unbounded (Key_Type => String, Element_Type => Ada.Text_IO.File_Type); [There's also a hashed version.] procedure Open (Set : in out File_Sets.Container_Type; Name : in String) is I : Iterator_Type; B : Boolean; begin Insert (Set, Name, I, B); if B then declare F : File_Type renames To_Access (I).all; begin Open (F, In_File, Name); end; else declare F : File_Type renames To_Access (I).all; begin if not Is_Open (F) then Open (F, In_File, Name); end if; end; end if; end Open; In you're interested, drop me a line. -Matt