wishlist Python3K: subclass ints

Moshe Zadka moshez at math.huji.ac.il
Fri Jun 9 03:57:07 EDT 2000


On 9 Jun 2000, Aahz Maruch wrote:

> Oh, I see.  Hmmmm....  That makes a lot of sense, yes.  I'm still having
> a little trouble wrapping my head around how this works with
> user-defined numeric types, but I'll let the people who are into
> metaclass programming deal with it.  ;-)

Oh, it doesn't really. I mean, the best you can do (in a type/class
dichotomy solved world), is inherit from "number", and change any of the
methods: but that wouldn't help you at all to implement constructive
reals the "right way".

on-the-other-hand-you-can-probably-use-this-to-implement-quaternions-ly
y'rs, Z.

(It's easy: simply define a quaternion as a pair (a, b) where a and b are
numbers, have coercion of quaternions defined by a --> (a, 0), and just
ask issubclass(number) about things (which quaternions are). OTOH, you'd
need interfaces and a better coercion architecture then what is in Python
right now to support this correctly)
--
Moshe Zadka <moshez at math.huji.ac.il>
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com





More information about the Python-list mailing list