Skip to content

Instantly share code, notes, and snippets.

@45deg
Created December 15, 2019 11:36
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 45deg/d022c3775c136262cb3bded30dd45002 to your computer and use it in GitHub Desktop.
Save 45deg/d022c3775c136262cb3bded30dd45002 to your computer and use it in GitHub Desktop.
import os
from multiprocessing import Pipe
class Continuation:
def __init__(self, cont):
self._cont = cont
def __call__(self, arg):
self._cont.send(arg)
exit(0)
def call_cc(f):
rx, tx = Pipe()
pid = os.fork() # 🍴
if pid:
# 👨
return f(Continuation(tx))
else:
# 👶
return rx.recv()
global_k = None
def f(k):
global global_k
print("f called")
global_k = k
return 0
if __name__ == "__main__":
print("f returns", call_cc(f))
if global_k:
global_k(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment