On Thu, Jun 5, 2008 at 1:18 PM, William Stein wrote:
> ...
> On Thu, Jun 5, 2008 at 12:23 PM, Gonzalo Tornaria wrote:
> ...
>> 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.

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.

Regards,
Bill Page.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to