comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
Subject: Adding "()" operator to Ada 200X
Date: Mon, 02 Jun 2003 16:35:01 GMT
Date: 2003-06-02T16:35:01+00:00	[thread overview]
Message-ID: <V0LCa.32473$ca5.11277@nwrdny02.gnilink.net> (raw)

There appears to be wide agreement that Ada 200X should include some sort of
standard container library like Charles and PragMark. This library will
probably include generic packages for creating and operating with dynamic
lists and maps. One can view these kinds of collections as generalized
arrays, and as such, it would be nice to use array notation for accessing a
member of one of these collections. In other words, one should be able to
define the "()" operator for array-like types, as follows:

    function "()" ( Source : in Array_Like_Type;
                    Index  : in Index_Type )
       return Component_Type;

For example, if the object Roster is a list of objects of type Player_Type,
it would be quite desirable to be able to access the second player in Roster
as

    Roster(2)

For that matter, we could use the "()" operator to improve some existing Ada
packages. The Ada.Strings.Bounded and Ada.Strings.Unbounded packages define
the types Bounded_String and Unbounded_String that are enhanced versions of
the String type. If Item is of type Bounded_String / Unbounded_String, we
now access the third character of Item using the expression

    Element( Item, 3 )

Again, why not use the same notation that we would use if Item were declared
as Standard.String (assuming that Item'First = 1 ), i.e.

    Item(3)

If Ada 200X had an "()" operator, we could add the following declaration to
Ada.Strings.Unbounded

    function "()" (Source : in Unbounded_String;
                   Index  : in Positive)
       return Character renames Element;

With this declaration, we could use either "Element( Item, 3 )" or "Item(3)"
to get the third element of Item.

Of course, an array component can also be assigned a value, as in

    Item(3) := 'A':

For that reason, we may also want to add an "():=" operator that is used to
update a component of an array-like object, e.g.

    procedure "():=" ( Source : in out Array_Like_Type;
                       Index  : in     Index_Type;
                       Value  : in     Component_Type );

Again, we could enhance packages such as Ada.Strings.Bounded and
Ada.Strings.Unbounded by declaring a "():=" operator that could be used in
place of the Replace_Element procedures.

I cannot help but think that this would be of tremendous help with whatever
standard container library is added to Ada 200X.





             reply	other threads:[~2003-06-02 16:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-02 16:35 Frank J. Lhota [this message]
2003-06-02 23:42 ` Adding "()" operator to Ada 200X 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
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