On Apr 28, 2009, at 12:37 AM, Hoyt Koepke wrote:

> Pardon me jumping into the discussion so late,

Never to late to jump in, and the more people we get feedback from  
the better the final result will be.

> and perhaps missing
> something too, but since I've done a lot of c++ coding, here's a few
> observations:
>
> 1.  It seems that the discussion of iterators and the discussion of
> implementing generators are pretty closely linked, at least for basic
> iterator types.  For the basic iterator types, I could see having a
> special generator type that accepts starting and ending iterator
> instances, or methods of the C++ class (such as .begin() and .end()
> for vector), as constructor arguments.  At this level they are
> conceptual quite similar, at least using the STL iterator concept.  It
> does not seem to me like accessing the iterators directly (e.g.
> through .inc) is needed if it is provided through fast C-level
> generators.  Most of the way the STL is stitched together is so
> conceptually similar to python generators, especially in Py3, that it
> should be part of this discussion, and the  C++ STL ideal is to
> minimize the need for low level operations on the iterators.  (Robert,
> I have a book on exactly the concepts of iterators and generic
> programming with the C++ STL if you'd like to borrow it for a while;
> I'll contribute what I can, but I'm really busy now.)

They are conceptually very similar, but very different implementation- 
wise. For generators we need closures, i.e. the ability to store an  
re-instantiate the (virtual) stack frame of a function call.  
Iterators are already implemented and we just need to be able to call  
them. (One can currently use generators just fine in Cython, we just  
can't create them).

Rather than inform Cython about (some subset of) C++ iterator  
semantics, the goal is to extend Cython to add C++ features to make  
it easy to wrap arbitrary C++ code. STL provides a very good test  
case--one should be able to use it in Cython the same way one uses it  
in C++.

Of course, eventually it would be nice to be able to "loop" over an  
iterator with a for-from or for-in loop.

> 2. Also, what types in the STL iterator type hierarchy should we
> support?  There are forward iterators, backward iterators,
> bidirectional iterators which generalize those, and random access
> iterators which generalize those.  In addition, there are reading and
> writing versions of these iterators.  Plus const/non-const version to
> worry about.  Big pain, I know, but seems like good c++ wrapping will
> have to deal with all this.  From experience, forward and backward
> iterators are the most common, with random access being next, though
> these all could perhaps be wrapped in other generator or class
> types...

If we enable using iterators as in C++, rather than trying to provide  
Cython wrappers for iterators, we don't need to know about all of  
these various types in the Cython compiler.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to