comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: Adding "()" operator to Ada 200X
Date: Thu, 05 Jun 2003 01:15:31 GMT
Date: 2003-06-05T01:15:31+00:00	[thread overview]
Message-ID: <3EDE998D.3060701@attbi.com> (raw)
In-Reply-To: wMqDa.34826$ca5.29447@nwrdny02.gnilink.net

Frank J. Lhota wrote:

> 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.

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.

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.






  reply	other threads:[~2003-06-05  1:15 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 [this message]
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