Thanks, looks good. Maybe one could factor out the Enumerated (=canonical enumeration) part? Or is every parent with __iter__ supposed to be in EnumeratedSets and, therefore, have a rank() methods etc? The element order is often just arbitrary...
Also, I dislike .list() returning a Python list. We should always return tuples, and if even the Sage framework breaks that rule then its very confusing for new users. An argument could be made that list can be understood as "Python list" and not as the English verb for "series of records". Maybe call it enumerate() with an alias list()? On Friday, November 9, 2012 7:42:42 AM UTC-5, Nicolas M. Thiéry wrote: > > Hi Volker, > > On Thu, Nov 08, 2012 at 08:02:49AM -0800, Volker Braun wrote: > > This occurred to me before, its nice to have iterators/generators but > > there should be a mechanism to say that the iterator is over a finite > or > > infinite set. > > Just to avoid doing exhaustive searches over infinite sets. > > Similar to C++ iterator traits, I guess. Of course if you were to > manually > > implement a generator as a Python class (implementing __next__) you > could > > attach other methods like is_finite(). But then you'd always have to > write > > a lot of boilerplate to return an iterator. Its much easier to use > yield, > > but then you can't return any additional information about > finiteness. > > The alternative is to assume that the user knows what he is doing > when he > > passes an iterator / generator object. V.sum(W) can and should still > check > > that W is finite before starting to iterate over W. > > There is already a bit of infrastructure for this; namely an parent > modeling an enumerated set which is infinite should declare itself in > the category InfiniteEnumeratedSets (soon to come: Sets().Infinite()). > Then, methods could do some checks on this; that's already the case > for e.g. ``list``:: > > sage: ZZ.list() > Traceback (most recent call last): > ... > ValueError: since it is infinite, cannot list Integer Ring > > Of course a preliminary step would be to make sure that parents are > put in this category when relevant. Here QQ^3 should not only be an > iterable but actually an infinite enumerated set: > > sage: (QQ^3) in InfiniteEnumeratedSets() # todo: not implemented > True > > More precisely: QQ^3 should be in the category of finite dimensional > modules with basis, and a finite dimensional module with basis over an > infinite field should be in the category of infinite enumerated sets. > > Cheers, > Nicolas > -- > Nicolas M. Thi�ry "Isil" <nth...@users.sf.net <javascript:>> > http://Nicolas.Thiery.name/ > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To post to this group, send email to sage-devel@googlegroups.com. To unsubscribe from this group, send email to sage-devel+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel?hl=en.