comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
Subject: Re: Adding "()" operator to Ada 200X
Date: Wed, 04 Jun 2003 18:21:16 GMT
Date: 2003-06-04T18:21:16+00:00	[thread overview]
Message-ID: <wMqDa.34826$ca5.29447@nwrdny02.gnilink.net> (raw)
In-Reply-To: 1ec946d1.0306040928.6eb47667@posting.google.com

"Matthew Heaney" <mheaney@on2.com> 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.





  reply	other threads:[~2003-06-04 18:21 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 [this message]
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