I think I understood it, but the example with continuations is still quite mind-blowing. I probably would have rewritten it like so:
import traceback def fib_cnt ( state ) : print(len(traceback.extract_stack()) * '*' + ": " + str(state)) if state['finished'] : return state if len(state['values']) == 0 : state['finished'] = True return state n = state['values'].pop() if n < 2: state['acc'] += 1 return state state['values'].append(n-1) state['values'].append(n-2) return state def fib (n) : state = dict ( values = [n], acc = 0, finished = False ) while not state['finished'] : state = fib_cnt(state) return state['acc'] print(fib(5))
This way most of the state is quite transparent and not hidden behind lambdas.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think I understood it, but the example with continuations is still quite mind-blowing.
I probably would have rewritten it like so:
This way most of the state is quite transparent and not hidden behind lambdas.