!7 cprint { class State extends ProbabilisticMachine2.State { IVF1 continuation; public State makeDescendant() { new State s; prepareDescendant(s); s.continuation = continuation; ret s; } void doneWithSubroutine { if (continuation == null) ret; IVF1 cont = continuation; addState(prepareDescendant(new State { run { cont.get(this); } })); } void step { doneWithSubroutine(); } } start-thread { new ProbabilisticMachine2 pm; Chain words = litchain("Hello", "World", "."); pm.addState(new State { printWords(words)); }); pm.onRunningState = st -> { print("Running state " + st); }; pm.onRanState = st -> { print("Ran state " + st); }; stepAllWithStats(pm); } State printWords(Chain words) { if (empty(words)) ret new State; State s = prepareDescendant(new { run { print(first(words)); addState(prepareDescendant(new State { run { dropFirst(words); doneWithSubroutine(); } }; s.continuation = state -> { print("World"); }; pm.addState(s); } }