Skip to content

Instantly share code, notes, and snippets.

@agumonkey
Created February 4, 2019 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agumonkey/9955e82373abb42cc2e6d9656bb5a4d2 to your computer and use it in GitHub Desktop.
Save agumonkey/9955e82373abb42cc2e6d9656bb5a4d2 to your computer and use it in GitHub Desktop.
# ~continuations in python
# from: https://www.ps.uni-saarland.de/~duchier/python/continuations.html
# more: https://duckduckgo.com/html?q=continuations%20in%20python
def sumc(x,y,k):
k(x+y)
def mulc(x,y,k):
k(x*y)
def f(x,k):
sumc(x,1, lambda i: mulc(i,i,k))
def callcc(f,c):
f(c,c)
def identity(x):
return x
def seq(f,g):
def seqf(v):
f(v)
return g(v)
return seqf
def call(v):
def callf(f):
return f(v)
return callf
callcc(lambda k,q: q(seq(print, call)(k)),lambda x: print(42))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment