On Tue, Dec 14, 2010 at 3:09 PM, Rob Beezer <goo...@beezer.cotse.net> wrote:
> Symptom:  The following code would appear to run forever, since the
> rationals define an iterator that never quits.
>
> QQ.list()
>
> I discovered this when I presumed that
>
> (QQ^2).list()
>
> would raise an error.  It doesn't.  So I patched the free module code
> so the iterator producing module elements would raise an error for a
> module over an infinite base ring.  That very nearly passed all tests,
> except it ran afoul of the category test suite.  A doctest for sets
> (in the  Set_object_union  class) constructs a vector space.  To get a
> generic element for testing the test suite would appear to build an
> iterator and then grab the first element produced, so my fix broke
> that.  (This appears to be at
> categories.enumerated_sets._an_element_from_iterator)
>
> It looks like  structure.parent._list_from_iterator_cached  is where
> the first examples get stuck, at least that looks like the right place
> when you read the code and that's part of the traceback when you use
> ctrl-C.
>
> Options:
>
> 1.  _list_from_iterator_cached  could ask if self is infinite and if
> so, fail.  This would break the test suite too, I think.
>
> 2.  The test suite framework needs to get an element by some other
> process.  For example, (QQ^2).an_element() did not break with my
> patch.
>
> 3.  Tough.  You ought to check if a set is infinite before you try to
> list it (and students should just learn to do that).
>
> 4.  Something else.
>
> I've attached one failure of the test suite from my patch to the
> module code, there were four very similar failures from the one test:
> _test_an_element, _test_elements, _test_elements_eq,
> _test_some_elements.  The last error message is from my patch.
>
> I'd started this as:  http://trac.sagemath.org/sage_trac/ticket/10470
>
> I would prefer to have modules raise an error rather than just hang.
> If desired, I can try to fix more fundamental situations, like
> ZZ.list().  Comments and suggestions appreciated.

I would strongly object to removing the ability to iterate over
infinite sets, sometimes it's very useful to iterate until something
is found, or to grab a certain number of elements. I would be OK with
ZZ.list() throwing an exception as long as "for x in ZZ" still worked
just fine.

- Robert

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to