comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Proposed change to BC iterator parameters
Date: Sat, 20 Dec 2003 14:08:00 -0500
Date: 2003-12-20T14:08:00-05:00	[thread overview]
Message-ID: <xbWdnX7HmtSPA3miRVn-vw@comcast.com> (raw)
In-Reply-To: <wcc65gcwhkb.fsf@shell01.TheWorld.com>

Robert A Duff wrote:

> Cursors are fine when you need that power, but if all you want to do is
> loop through the elements of a data structure, it's too low level.  The
> client shouldn't have to worry about getting the next thing, and testing
> for done.  The client should just say "for each item X, perform
> so-and-so operations on X".  That's pretty much what the generic style
> does, but the syntax is horrible, and it doesn't work in all cases.  For
> example, as Jeff Carter pointed out, if the iterator wants to be a
> protected operation.

I'm a big fan of asking for what you want, then seeing if what you get 
satisfies your need.

Right now I can say:

for I in A'Range loop
   Do_Something(A(I));
end loop;

or

while List.Next /= null loop;
   List := List.Next;
   Do_Something(List.Data);
end loop;

What Bob seems to be asking for is a way to do that for general data 
structures:

package My_Structures is new Some_Structure(Element);

type My_Structure renames My_Structures.Structure;

for E in My_Structures.Ordered_List_of_Elements loop
   Do_Something(E);
end loop;

Currently I often provide tools in my data structures packages to 
provide everything viewed as an array.  This allows me to do what Bob 
wants, but it would be really nice to extend the language so that 
iterators are first class objects known to the language so that the 
above pseudo code (for E in ...) would be supported if the 
Some_Structure package provided an iterator.  You should also be able to say

if E in My_Structures.Some_Iterator then ...

(This would require another signature in the template for iterators to 
make it efficient.)

Do I think this will make it into Ada 0Y?  No.  Ada 1Z? Possibly.

But the trick of having data structure packages return an array view of 
a collection, or actually an array of access values, is very, very 
useful.  (Notice that the difference between such an iterator and normal 
iterators is that it provides a snapshot.  Changes to the actual data 
structure while iterating through the array won't be visible in the 
loop.  Often this is what you want.  Sometimes it isn't, then it gets 
painful...)

-- 
                                           Robert I. Eachus

"The war on terror is a different kind of war, waged capture by capture, 
cell by cell, and victory by victory. Our security is assured by our 
perseverance and by our sure belief in the success of liberty." -- 
George W. Bush




  parent reply	other threads:[~2003-12-20 19:08 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-10 13:36 Proposed change to BC iterator parameters amado.alves
2003-12-10 16:47 ` Proposed change to BC iterator parameters [limitedness] Georg Bauhaus
2003-12-10 17:39 ` Proposed change to BC iterator parameters Martin Krischik
2003-12-10 18:22 ` Jeffrey Carter
2003-12-10 23:00   ` Robert A Duff
2003-12-11  1:00     ` Jeffrey Carter
2003-12-11 15:09       ` Robert A Duff
2003-12-11  8:33     ` Dmitry A. Kazakov
2003-12-10 20:50 ` Simon Wright
2003-12-10 23:12 ` Robert A Duff
2003-12-11  5:07   ` Steve
2003-12-11 15:24     ` Robert A Duff
2003-12-11 17:39       ` Jeffrey Carter
2003-12-12 22:22         ` Robert A Duff
2003-12-13  0:57           ` Jeffrey Carter
2003-12-17 20:59             ` Robert A Duff
2003-12-18 10:05               ` Dmitry A. Kazakov
2003-12-18 18:14                 ` Robert A Duff
2003-12-19 10:53                   ` Dmitry A. Kazakov
2003-12-19 16:17                     ` Georg Bauhaus
2003-12-19 17:19                       ` Dmitry A. Kazakov
2003-12-19 22:51                         ` Robert A Duff
2003-12-20 12:20                           ` Dmitry A. Kazakov
2003-12-19 22:47                       ` Robert A Duff
2003-12-20  2:11                         ` Stephen Leake
2003-12-20 19:08                         ` Robert I. Eachus [this message]
2003-12-21 11:39                           ` Simon Wright
2003-12-21 18:13                             ` Robert I. Eachus
2003-12-21 13:58                           ` Dmitry A. Kazakov
2003-12-22  1:25                             ` Robert I. Eachus
     [not found]         ` <916oa1-c93.ln1@beastie.ix.netcom.com>
2003-12-13 16:57           ` Simon Wright
2003-12-12  5:29     ` Simon Wright
2003-12-12 22:26       ` Robert A Duff
2003-12-13 16:55         ` Simon Wright
2003-12-13 17:27           ` Dmitry A. Kazakov
2003-12-13  2:44       ` Steve
  -- strict thread matches above, loose matches on Subject: below --
2003-12-23 10:40 amado.alves
2003-12-19 15:53 amado.alves
2003-12-19 23:05 ` Robert A Duff
2003-12-11 16:02 amado.alves
2003-12-11 15:05 ada_wizard
2003-12-11 16:45 ` Robert A Duff
2003-12-11 12:56 amado.alves
2003-12-17 20:25 ` Robert A Duff
2003-12-11 12:43 amado.alves
2003-12-11 12:33 amado.alves
2003-12-10 14:39 amado.alves
2003-12-10  5:46 Simon Wright
2003-12-10 18:12 ` Jeffrey Carter
2003-12-11 16:10   ` Martin Krischik
2003-12-10 20:59 ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox