>>> sage: def classinteger(m): >>> ... class A: >>> ... def __init__(self, n): >>> ... self.__n = n % m >>> ... def __repr__(self): >>> ... return "%d mod %d" % (self.__n, m) >>> ... A.__name__ = "classintegers mod %d" % m >>> ... return A >>> sage: classinteger(5)(3) >> ... >> OK, I have to come clean and admit that already actually knew >> all about metaclasses, but considered using them this way so >> unnatural and ugly that I would not recommend it. >> > > Do you still consider the example code like that given above by > Gonzalo "unnatural and ugly"? It seems like pretty standard Python to > me. There of course various ways of packaging the metaclass machinery > to provide an even cleaner user interface.
To me, that feels much more "unnatural and ugly" than the current situation. Perhaps that's just because I'm used to things the way they are currently. > The point I am making is that Python already has everything you need > to implement the concept of the "parent" of an element as a type, i.e. > directly as an instance of the class that creates it. This could > result in considerable simplification compared to the current > situation. Right now a Sage user has to deal with three separate > type-related concepts: type (Python class), parent (an object in some > category) and category. Metaclasses are a good match for Categories. > Thus you can have everything in one package and remain closer to > conventional Python programming in spirit. For me, a class represents an implementation / model of a mathematical object whether it be a multivariate polynomial or a multivariate polynomial ring. I don't see why one would want to tie the implementation of the parent structure together with that of its elements. In your setup, I'm still not sure where place things like .multiplicative_generators(). Sure, you could make it a class method so that you don't need an instance to access it, but then all of that class's instance have that method which was not the intention. --Mike --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---