Re: Problems with CPS'ing python functions

Steven Miale (smiale@cs.indiana.edu)
Fri, 27 May 1994 11:31:37 -0500

To followup to my own post: this can be done using classes, but
it still doesn't seem to affect the main problem (i.e. that local
functions cannot access variables defined in their 'father'
function.)

class FactCPS:
def __init__(self, n, k):
self.k=k
self.n=n
def run(self):
if self.n==0:
return self.k(1)
else:
return factcps(self.n-1, self.cps)
def cps(self, v):
return self.k(self.n*v)

def factcps(n,k):
return FactCPS(n,k).run()

>>> def pr(v):
... print v
...
>>> factcps(5,pr)
120

Steve

-- 
Steven Miale - smiale@cs.indiana.edu| I was there at the dawn of the third age
Indiana University, Bloomington, IN | of man, and all I got was this lousy .sig