mutable default parameter problem [Prothon]
Mark Hahn
mark at prothon.org
Fri Jun 18 15:34:32 EDT 2004
Hung Jung Lu wrote:
> In code refactoring, the equivalent is to replace conditional
> statements by polymorphism. In terms of codeblocks, what I mean is
> dynamic hook-on and hook-off of codeblocks. If the underlying language
> is powerful enough, one should be able to achieve runtime
> restructuring of code, without performance impact for subsequent
> calls.
What about this Prothon code:
def f():
if 'static' not in f.attrs_:
f.static = 0
f.static += 1
tmp = f.static
def outer.f():
f.static += 1
return f.static
f.static = tmp
return f.static
print f() # 1
print f() # 2
print f() # 3
I'm sure Python can do this better so please don't barrage me with replies
saying so. I'm not going to brag this time :-)
More information about the Python-list
mailing list