[Python-Dev] Candidate Function Decorator
Raymond Hettinger
raymond.hettinger at verizon.net
Tue Apr 13 07:56:27 EDT 2004
I worked out the details for binding constants and posted a recipe to
ASPN:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940
Example:
[bind_constants]
def biased_dotprod(v1, v2):
sum = 0
for i in xrange(min(len(v1), len(v2)):
sum += v1[i] * (v2[i] - bias)
return sum
The decorate function binds globals that are known at compile time. So,
"xrange", "min", and "len" are added to the constant table, but bias is
left as a global lookup (unless it was already defined somewhere before
the function definition).
The chief advantage of this construct to avoid code like: _len=len,
while still getting all of the advantages. The modules in the sre
package are prime candidates for taking advantage of constant binding.
Raymond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20040413/d8a1937f/attachment.html
More information about the Python-Dev
mailing list