Hi Jean-Yves, I'm very happy to see you starting to use sage and giving us constructive feedback.
On Wed, Jan 23, 2013 at 11:31:37PM -0800, Jean-Yves Thibon wrote: > > The problem is that, for the average user, Partitions(n), or > Compositions(n), or > Whatever(n) is expected to behave like, say, xrange(n). Removing __len__ > breaks basic > python functionalities, results in head scratching ("What am I doing > wrong?"), > and drives the user to a hack-oriented programming style. I'm not sure to agree with that. I also think, you are not an average Sage user, you know way too much of Python. In this case "xrange(n)" is an iterator, that is a Python/computer stuff, whereas Partitions(n) models the sets of all partitions of n. > For algebraic purposes, I have never seen partitions of more than 25 or > compositions > of more than 16, let alone permutations of more than 14 . > For number theory or enumerative combinatorics, one needs much larger > values, > but a user trying to generate more than > 2**62 = 4611686018427387904 objects will probably accept an overflow error. > > So, why not let __len__ try to return int(cardinality) and throw and > exception if it is too large? The main problem i see with that is that in many time cardinality is implemented by running through the element... A similar problem is that I've no way to prevent the user to write: sage: list(Partitions()) ... infinite loop which is closely related to sage: len(Partitions()) ... AttributeError: __len__ has been removed; use .cardinality() instead whereas I'd like to teach him as soon as possible to write sage: Partitions().list() [...] NotImplementedError: infinite list sage: Partitions().cardinality() +Infinity which both are fast to answer an perfectly makes sense. I've the feeling that keeping the len stuff leads to more confusion for mathematician (not for Python programmer). Cheers, Florent -- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To post to this group, send email to sage-combinat-devel@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.