2014-08-26 15:22 UTC+02:00, William A Stein <wst...@uw.edu>:
> On Tue, Aug 26, 2014 at 3:12 PM, John Cremona <john.crem...@gmail.com>
> 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.

But I really will not use it myself because it has a classcall,
UniqueRepresentation, category, etc which takes lifetime to
initialize. 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.

Vincent

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to