comp.lang.ada
 help / color / mirror / Atom feed
* iterators as  first class objects
@ 2003-12-22 16:19 Lionel.DRAGHI
  2003-12-22 21:37 ` Robert I. Eachus
  0 siblings, 1 reply; 2+ messages in thread
From: Lionel.DRAGHI @ 2003-12-22 16:19 UTC (permalink / raw)
  To: comp.lang.ada



| -----Message d'origine-----
| De: Robert I. Eachus 
...
| 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.

I also really like this idiom, but there are drawbacks:

1 - you get more job done:
First within the data structure component, you have to build the array. 
If the internal structure is not already an array, you will probably need an
actual iterator.
Then, within the user's code, there is the "for i in " loop.
With an iterator, there is only one loop.

2 - within the component, the whole array is build: with an iterator, you
may exit before the end.

This is why we use it only for small data structure. 

As this leads to crystal-clear user's code, and as it's a common need, I
think it's worth thinking about langage extension.
   
-- 
Lionel Draghi



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: iterators as  first class objects
  2003-12-22 16:19 iterators as first class objects Lionel.DRAGHI
@ 2003-12-22 21:37 ` Robert I. Eachus
  0 siblings, 0 replies; 2+ messages in thread
From: Robert I. Eachus @ 2003-12-22 21:37 UTC (permalink / raw)


Lionel.DRAGHI@fr.thalesgroup.com wrote:

> 2 - within the component, the whole array is build: with an iterator, you
> may exit before the end.
> 
> This is why we use it only for small data structure. 
> 
> As this leads to crystal-clear user's code, and as it's a common need, I
> think it's worth thinking about langage extension.

Which is why, as I said elsewhere I usually provide both the array view 
and a global next operation.  It is not an iterator because it removes 
the object from the structure before returning it.

If you want to think of this as an array view, and a queue view, fine, 
although the Next operation maps well to all data structures.  (If the 
user doesn't care about order (a bag) he still gets one item at a time 
with no repetition.


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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-12-22 21:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-22 16:19 iterators as first class objects Lionel.DRAGHI
2003-12-22 21:37 ` Robert I. Eachus

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