iterators as first class objects

Lionel.DRAGHI_at_fr.thalesgroup.com
Date: 12/22/03


Date: Mon, 22 Dec 2003 17:19:22 +0100
To: comp.lang.ada@ada-france.org


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


Relevant Pages

  • Re: Proposed change to BC iterator parameters
    ... > loop through the elements of a data structure, ... provide everything viewed as an array. ... Some_Structure package provided an iterator. ...
    (comp.lang.ada)
  • Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)
    ... > while Has_Element loop ... > container, the passive iterator is preferred: ... > If you have an array type, then you can give it a container-like ...
    (comp.lang.ada)
  • Re: Latest version of glossary
    ... such as XML, refer to the use of the term within that "namespace" using ... An n-dimensional data structure, S, is one where each element of S ... Whenever mathematics is applied to anything, ... associative array (while trying to do something in JavaScript, ...
    (comp.databases.theory)
  • Re: Question about graph theroy--Help!
    ... the source and destination may be the same node. ... if it has visited that node before (loop). ... A data structure for a path would have: ... - fixed array of 254 bytes ...
    (comp.soft-sys.matlab)
  • Re: how to read dynamic data structures from the kernel (was Re: reading routing table)
    ... could give us individual entries of the data structure on each call, ... steps for any given kernel subsystem -- we have data structures, ... bumping the references and adding pointers to the array. ... the global locks, and proceed lock, externalize, unlock, and copyout each ...
    (freebsd-net)