comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Adding "()" operator to Ada 200X
Date: 9 Jun 2003 07:15:37 -0700
Date: 2003-06-09T14:15:38+00:00	[thread overview]
Message-ID: <1ec946d1.0306090615.a9870ff@posting.google.com> (raw)
In-Reply-To: uy5Ea.14478$b8.437@nwrdny03.gnilink.net

"Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> wrote in message news:<uy5Ea.14478$b8.437@nwrdny03.gnilink.net>...
> 
> This would dovetail nicely with the idea of an Ada iterator schemes. The
> "range" object could encapsulate the notion of an oredered list of values.
> Each Range object would a 'First element and a 'Last element, as well as the
> 'Succ / 'Pred functions to move forward / backward through the values in the
> range. 

You can already do this.  In the Charles library, every container is
indeed "an ordered list of values," which you can navigate using
either active or passive iterators.

Each container has selector functions that return iterator objects
designating the first and last elements in the container (and keys, if
this is a map), as well as the nonce elements immediately after the
last element and immediately before the first element.


> If Ada 200X had a range object, it would be nice to be able to define
> the "in" operator for it. Moreover, it would be great if the "for" loop
> could work with range objects, i.e.
> 
>     for I in Range_Object loop ... end loop;
> 
> would execute the loop body with I set to each value in Range_Object,
> visited in Forward order, starting at 'First and ending with 'Last.

Just do this:

procedure Op (C : Container_Subtype) is
   I : Iterator_Type := First (C);
   J : constant Iterator_Type := Back (C);
begin
   while I /= J loop
      declare
         E : constant Element_Type := Element (I);
      begin
         Do_Someting (E);
      end;

      I := Succ (I);
   end loop;
end Op;

--or this:

procedure Op (C : Container_Subtype) is

   procedure Iterate is
     new Generic_Select_Elements (Do_Something);
begin
   Iterate (First (C), Back (C));
end Op;



> Similarly
> 
>     for I in reverse Range_Object loop ... end loop;
> 
> would visit the values in Range_Objec in reverse order, i.e. starting with
> 'Last, then moving towards 'First using the 'Pred function.

Just do this:

procedure Op (C : Container_Subtype) is
   I : Iterator_Type := Last (C);
   J : constant Iterator_Type := Front (C);
begin
   while I /= J loop
      declare
         E : constant Element_Type := Element (I);
      begin
         Do_Someting (E);
      end;

      I := Pred (I);
   end loop;
end Op;

--or this:

procedure Op (C : Container_Subtype) is

   procedure Iterate is
     new Generic_Reverse_Select_Elements (Do_Something);
begin
   Iterate (Last (C), Front (C));
end Op;

No change in Ada language syntax is necessary.



  reply	other threads:[~2003-06-09 14: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
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 [this message]
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