Transpiled version (3111L) is out of date.
!7 cprint { class State extends ProbabilisticMachine2.State { IVF1<State> continuation; public State makeDescendant() { new State s; prepareDescendant(s); s.continuation = continuation; ret s; } void doneWithSubroutine { if (continuation == null) ret; IVF1<State> cont = continuation; addState(prepareDescendant(new State { run { cont.get(this); } })); } void step { doneWithSubroutine(); } } start-thread { new ProbabilisticMachine2<State> pm; Chain<S> 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<S> 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); } }
Began life as a copy of #1030671
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030672 |
Snippet name: | ProbabilisticMachine2 with continuations Spike [dev.] |
Eternal ID of this version: | #1030672/16 |
Text MD5: | e5127aa35eba961e91ebcf443f58212c |
Author: | stefan |
Category: | javax / gazelle |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-02-25 23:02:02 |
Source code size: | 1321 bytes / 62 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 228 / 429 |
Version history: | 15 change(s) |
Referenced in: | [show references] |