Re: self modifying code
- From: Robin Becker <robin@xxxxxxxxxxxxxxxxxxx>
- Date: Sat, 29 Apr 2006 19:01:14 +0000
John J. Lee wrote:
1. I don't think most people would call that "self-modifying code". I
won't try defining that term precisely because I know you'll just
pick holes in my definition ;-)
Don't really disagree about the rewriting code, but the function does re-define itself.
2. The use of global func is just plain weird :-)........
3. Peter Otten's version is OK, but how about this, using a closure
instead of globals (UNTESTED)
def make_func():
namespace = object()
namespace.data = None
def func(a):
if namespace.data is None:
namespace.data = somethingcomplexandcostly()
return simple(namespace.data, a)
return func
func = make_func()
the inner function is almost precisely what I started with, except I used the global namespace. However, it keeps the test in side the function which costs about 1%.
--
Robin Becker
.
- References:
- self modifying code
- From: Robin Becker
- Re: self modifying code
- From: John J. Lee
- self modifying code
- Prev by Date: Re: Urllib2 / add_password method
- Next by Date: Re: A QFB agent: how to catch C-level crashes and last Python stack ?
- Previous by thread: Re: self modifying code
- Next by thread: Re: self modifying code
- Index(es):
Relevant Pages
|