proc A def/calls proc B: variable scoping rules.

NevilleDNZ nevillednz at gmail.com
Tue Aug 15 23:28:34 EDT 2006


Steve Holden wrote:
> No. It's too horrible to contemplate without getting mild feelings of
> nausea. What exactly is it you are tring to achieve here (since I assume
> your goal wasn't to make me feel sick :-)?

It is part of an algorithum:
#!/usr/bin/env python
def A(k, x1, x2, x3, x4, x5):
  def B():
    k = k - 1;
    B.out=A.out=A(k, B, x1, x2, x3, x4)
    return B.out
  if k <= 0: A.out = x4 + x5
  else: B()
  return A.out
print A(10, 1, -1, -1, 1, 0);
#   correct output is -67

The scope of k remains one problem, as it is passed as an argument to
A.

I think x1,x2,x3,x4 are meant to be lambdas as well... :-)
N




More information about the Python-list mailing list