Re: Ternary plus

2010-02-10 Thread Mark Dickinson
On Feb 10, 8:31 am, Mark Dickinson wrote: > And here's how it's used in the decimal.Context module: Aargh! decimal.Context *class*, not module. And it occurs to me that it would have been cleaner to have Decimal.__add__ call Context.add rather than the other way around. Then Decimal.__add__ cou

Re: Ternary plus

2010-02-10 Thread Mark Dickinson
On Feb 9, 6:47 pm, Martin Drautzburg wrote: > BTW I am not really trying to add three objects, I wanted a third object > which controls the way the addition is done. Sort of like "/" and "//" > which are two different ways of doing division. That seems like a reasonable use case for a third param

Re: Ternary plus

2010-02-09 Thread Gabriel Genellina
En Tue, 09 Feb 2010 15:47:43 -0300, Martin Drautzburg escribió: Carl Banks wrote: You can have __add__ return a closure for the first addition, then perform the operation on the second one. Example (untested): That's way cool. Of course! - CURRYING!! If you can return closures you can

Re: Ternary plus

2010-02-09 Thread Martin Drautzburg
Carl Banks wrote: > You can have __add__ return a closure for the first addition, then > perform the operation on the second one. Example (untested): > > class Closure(object): > def __init__(self,t1,t2): > self.t1 = t1 > self.t2 = t2 > def __add__(self,t3): > #

Re: Ternary plus

2010-02-08 Thread Carl Banks
On Feb 8, 12:59 pm, Martin Drautzburg wrote: > Just for the hell of it ... > > I can easily define __plus__() with three parameters. If the last one is > optional the + operation works as expected. Is there a way to pass the > third argument to "+" If, for some reason, you wanted to define a type

Re: Ternary plus

2010-02-08 Thread Steven D'Aprano
On Mon, 08 Feb 2010 21:59:18 +0100, Martin Drautzburg wrote: > Just for the hell of it ... > > I can easily define __plus__() with three parameters. If the last one is > optional the + operation works as expected. Is there a way to pass the > third argument to "+" How do you give three operands

Re: Ternary plus

2010-02-08 Thread Robert Kern
On 2010-02-08 14:59 PM, Martin Drautzburg wrote: Just for the hell of it ... I can easily define __plus__() with three parameters. If the last one is optional the + operation works as expected. Is there a way to pass the third argument to "+" No. -- Robert Kern "I have come to believe that t

Ternary plus

2010-02-08 Thread Martin Drautzburg
Just for the hell of it ... I can easily define __plus__() with three parameters. If the last one is optional the + operation works as expected. Is there a way to pass the third argument to "+" -- http://mail.python.org/mailman/listinfo/python-list