Continuations in python

python

Solution

my question is more in the line of if continuations are supported in python then how can they be expressed?

They are expressed the same way in Python as in any other language without call/cc: by passing a function as the continuation argument to another function. Consider the very silly example of a continuation that is applied to the sum of two numbers. In ML, you might write

fun plus(x, y, k) = k(x + y)

plus(2, 4, print o Int.toString)

which prints 6.

but in Python you might write

def plus(x, y, k):
    return k(x + y)

plus(2, 4, lambda n: print '%d' % n)

which also prints 6.

Problem

is there any equivalent construct for continuations in python. I have been reading about continuations and am just being curious and want to know as there is nothing about that in the docs.

Original source