Re: [Python-3000] Use case for generics

2006-05-14 Thread Georg Brandl
Greg Ewing wrote: > Talin wrote: > >> r = Rectangle( x, y, w, h ) >> r = Rectangle( minpos, maxpos ) >> r = Rectangle( position, size ) > > This sort of thing is better done in Python using > keyword arguments: > >Rectangle(left = x, top = y, width = w, height = h) >Rectan

Re: [Python-3000] Math in Python 3.0

2006-05-14 Thread Antoine Pitrou
Le dimanche 14 mai 2006 à 11:01 +1000, Nick Coghlan a écrit : > Fredrik Johansson wrote: > > For example, square roots are known as math.sqrt(x) for floats, > > cmath.sqrt(x) for complex numbers, x.sqrt() for decimals, and > > gmpy.sqrt(x)/gmpy.fsqrt(x) for gmpy's types. Oh, and SciPy has its own >

Re: [Python-3000] Math in Python 3.0

2006-05-14 Thread Giovanni Bajo
Martin v. Löwis <[EMAIL PROTECTED]> wrote: >> @overloaded >> def sqrt(value): >> raise TypeError("Cannot take square root of %s" % >> type(value).__name__) >> >> @sqrt.overload >> def sqrt_float(value : float): >> return math.sqrt(value) >> >> @sqrt.overload >> def sqrt_complex(value : com

Re: [Python-3000] Math in Python 3.0

2006-05-14 Thread Giovanni Bajo
Nick Coghlan <[EMAIL PROTECTED]> wrote: >> For example, square roots are known as math.sqrt(x) for floats, >> cmath.sqrt(x) for complex numbers, x.sqrt() for decimals, and >> gmpy.sqrt(x)/gmpy.fsqrt(x) for gmpy's types. Oh, and SciPy has its >> own sqrt function that works on arrays (but not Decim

Re: [Python-3000] Math in Python 3.0

2006-05-14 Thread Martin v. Löwis
Giovanni Bajo wrote: >>> @overloaded >>> def sqrt(value): >>> raise TypeError("Cannot take square root of %s" % >>> type(value).__name__) >>> >>> @sqrt.overload >>> def sqrt_float(value : float): >>> return math.sqrt(value) >>> >> So where would that sqrt function live? > > "math" would be

Re: [Python-3000] Math in Python 3.0

2006-05-14 Thread Paul Moore
On 5/14/06, Giovanni Bajo <[EMAIL PROTECTED]> wrote: > So, are we totally dropping the "special-cased __ method" that worked so fine > till now? I can "overload" abs() for my point type (to return its modulus) > just > by defining a __abs__, and it works fine. In such a world (called Python 2.x),

Re: [Python-3000] Math in Python 3.0

2006-05-14 Thread Nick Coghlan
Paul Moore wrote: > (FWIW, I like function overloading, and I'd love to see language or > stdlib support. I can see the arguments for using it in place of > existing special methods, but I'm nervous of the extent of that > change. If I had to decide *right now*, I'd go for adding overloading, > but

Re: [Python-3000] Math in Python 3.0

2006-05-14 Thread Giovanni Bajo
Nick Coghlan <[EMAIL PROTECTED]> wrote: >> (FWIW, I like function overloading, and I'd love to see language or >> stdlib support. I can see the arguments for using it in place of >> existing special methods, but I'm nervous of the extent of that >> change. If I had to decide *right now*, I'd go fo

Re: [Python-3000] Math in Python 3.0

2006-05-14 Thread Georg Brandl
Martin v. Löwis wrote: > Giovanni Bajo wrote: @overloaded def sqrt(value): raise TypeError("Cannot take square root of %s" % type(value).__name__) @sqrt.overload def sqrt_float(value : float): return math.sqrt(value) >>> So where would that sqrt

Re: [Python-3000] Use case for generics

2006-05-14 Thread tomer filiba
Edward Loper wrote: > For this use case, I don't think that a direct translation of the > overloaded-constructor design for C++ carries over into Python as a good > design. In particular, I think this would be better coded in Python > using either keyword arguments, or factory methods. I.e., I'd