From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Adding "()" operator to Ada 200X
Date: 5 Jun 2003 10:25:28 -0700
Date: 2003-06-05T17:25:28+00:00 [thread overview]
Message-ID: <1ec946d1.0306050925.c16e3c3@posting.google.com> (raw)
In-Reply-To: 3EDE998D.3060701@attbi.com
"Robert I. Eachus" <rieachus@attbi.com> 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
next prev parent reply other threads:[~2003-06-05 17:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-02 16:35 Adding "()" operator to Ada 200X Frank J. Lhota
2003-06-02 23:42 ` Matthew Heaney
2003-06-03 14:59 ` Frank J. Lhota
2003-06-03 15:09 ` Frank J. Lhota
2003-06-03 16:04 ` Martin Krischik
2003-06-04 17:28 ` Matthew Heaney
2003-06-04 18:21 ` Frank J. Lhota
2003-06-05 1:15 ` Robert I. Eachus
2003-06-05 14:59 ` Frank J. Lhota
2003-06-05 17:25 ` Matthew Heaney [this message]
2003-06-03 20:24 ` Randy Brukardt
2003-06-03 19:52 ` Francisco Javier Loma Daza
2003-06-03 2:56 ` Fionn mac Cuimhaill
2003-06-03 14:02 ` Matthew Heaney
2003-06-03 16:23 ` Mário Amado Alves
2003-06-05 19:02 ` Dmitry A. Kazakov
2003-06-06 10:56 ` Mário Amado Alves
2003-06-06 16:55 ` Chad R. Meiners
2003-06-06 19:01 ` Frank J. Lhota
2003-06-09 14:15 ` Matthew Heaney
2003-06-07 8:36 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox