Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Created August 22, 2012 18:48
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pervognsen/8dafe21038f3b513693e to your computer and use it in GitHub Desktop.
Save pervognsen/8dafe21038f3b513693e to your computer and use it in GitHub Desktop.
dataflow.py
inf = float("+inf")
def fix(bottom, n=inf, unwrap=lambda x: x):
if not callable(bottom):
bottom_value = bottom
bottom = lambda *args: bottom_value
def decorator(f):
def f_fix(*args):
me = (f_fix, args)
if not fix.calling:
value, fix.values[me] = None, bottom(*args)
i = 0
while i < n and value != fix.values[me]:
fix.calling.add(me)
value, fix.values[me] = fix.values[me], unwrap(f(*args))
fix.calling.clear()
i += 1
return value
if me in fix.calling:
return fix.values.get(me, bottom(*args))
fix.calling.add(me)
value = fix.values[me] = unwrap(f(*args))
fix.calling.remove(me)
return value
return f_fix
return decorator
fix.calling = set()
fix.values = {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment