[Tutor] Re: Python vs. Ruby

Andrei project5 at redrival.net
Fri Oct 31 10:32:52 EST 2003


Abel Daniel wrote on Fri, 31 Oct 2003 15:57:20 +0100:

> Andrei  writes:
>> class Fun:
>>     def __init__(self, *funcs):
>>         self.funcs = []
>>         self.funcs.extend(funcs)
>>     def __add__(self, func):
>>         self.funcs.extend(func.funcs)
>>         return Fun(*self.funcs)
>>     def __call__(self, *args):
>>         results = [ f(*args) for f in self.funcs ]
>>         return sum(results)
>>
> 
> This will behave suprisingly:
> 
>>>>import math
>>>>sin=Fun(math.sin)
>>>>cos=Fun(math.cos)
>>>>f = sin + cos
>>>>print sin(1)
> will give the wrong result.
> 
> Doing C = A + B shouldn't change A or B.

Good point. I hadn't done any testing beyond what I'd posted.


-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
ernq gur yvfg, fb gurer'f ab arrq gb PP.




More information about the Tutor mailing list