On Tue, Aug 26, 2014 at 3:49 PM, Vincent Delecroix <[email protected]> wrote: > 2014-08-26 15:22 UTC+02:00, William A Stein <[email protected]>: >> On Tue, Aug 26, 2014 at 3:12 PM, John Cremona <[email protected]> >> wrote: >>> Sounds like a reasonable plan if you (or someone) can be bothered to >>> sort out the chenges which will need to be made in code and doctests! >> >> Even then, personally I don't like it. See below for a different >> suggestion that is less intrusive. >> >>> There will be places where we now have: for p in primes(10^8): >>> do_something_with(p) which will still work when primes() returns a >>> list, so will not result in doctest failures, but which should be >>> changed. This will be rather tedious. >>> >>> On the plus side, I make the point that all these are functions at the >>> top level which will be discovered by beginners for whom >>> >>> sage: primes(100) >>> <generator object primes at 0x7f9335465a50> >>> >>> will just confuse. Experts can know about and use the iterator forms >>> of the functions. >> >> We could certainly make it do this with little effort: >> >> sage: P = primes(100); P >> Prime numbers of less than 100 >> >> We could then have >> >> for x in P: >> ... >> >> be the usual iterator. One could also do: >> >> sage: P.list() >> [...] >> >> to get back a list. And one could do >> >> sage: len(P) >> >> to get the number of primes, without computing them. So... my >> counterproposal is to make primes return a cython class with a few >> methods. This breaks new code, and will be more new user friendly. > > We already have Primes (upper case P) for that... it just need to be > tuned to accept lower/upper bounds. It is nicer from the user point of > view (as far as OOP is better than functional programming). A good > solution for the namespace would be to have only Primes and > PrimePowers. >
Primes is the set of all primes. It has little to do with this discussion. > But I really will not use it myself because it has a classcall, > UniqueRepresentation, category, etc which takes lifetime to > initialize. I'm proposing having only one cython-level function called "primes" that returns a Cython class. That class would no more take a lifetime to initialize than elements of ZZ, etc. Remember that every fast element in Sage is a Cython class. > My loops are rather small but I have plenty of them... so > having a nice Primes object would only be painful. I want to keep a > simple Cython function that returns list or iterator. Cython also supports simple fast classes. > > Vincent > > -- > You received this message because you are subscribed to the Google Groups > "sage-nt" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send an email to [email protected]. > Visit this group at http://groups.google.com/group/sage-nt. > For more options, visit https://groups.google.com/d/optout. -- William Stein Professor of Mathematics University of Washington http://wstein.org [email protected] -- You received this message because you are subscribed to the Google Groups "sage-nt" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send an email to [email protected]. Visit this group at http://groups.google.com/group/sage-nt. For more options, visit https://groups.google.com/d/optout.
