def factcps(n, k):
return factcps(n-1,lambda v:k(n*v))
def factcps2(n, k):
(for the record, equivalent Scheme code is:
(lambda (n k)
(if (zero? n)
(fact-cps (- n 1)
(lambda (v) (k (* n v)))))))
In both cases, accessing 'k' on the way back gives a NameError. In
other words, it gets to "return k(1)", but that return results in
calling k again ("return k(n*v)"), and neither k nor v are bound.
>From what I can gather, the local functions cps (in factcps2) and the
lambda (in factcps) are unable to access the environment of factcps2
and factcps, respectively.
Any ideas on how to solve the problem?
-- Steven Miale - firstname.lastname@example.org | Don't blame me - Indiana University, Bloomington, IN | I voted Libertarian.