Transpiled version (3111L) is out of date.
1 | !7 |
2 | |
3 | cprint { |
4 | class State extends ProbabilisticMachine2.State { |
5 | IVF1<State> continuation; |
6 | |
7 | public State makeDescendant() { |
8 | new State s; |
9 | prepareDescendant(s); |
10 | s.continuation = continuation; |
11 | ret s; |
12 | } |
13 | |
14 | void doneWithSubroutine { |
15 | if (continuation == null) ret; |
16 | IVF1<State> cont = continuation; |
17 | addState(prepareDescendant(new State { |
18 | run { |
19 | cont.get(this); |
20 | } |
21 | })); |
22 | } |
23 | |
24 | void step { |
25 | doneWithSubroutine(); |
26 | } |
27 | } |
28 | |
29 | start-thread { |
30 | new ProbabilisticMachine2<State> pm; |
31 | Chain<S> words = litchain("Hello", "World", "."); |
32 | pm.addState(new State { |
33 | printWords(words)); |
34 | }); |
35 | |
36 | pm.onRunningState = st -> { |
37 | print("Running state " + st); |
38 | }; |
39 | pm.onRanState = st -> { |
40 | print("Ran state " + st); |
41 | }; |
42 | stepAllWithStats(pm); |
43 | } |
44 | |
45 | State printWords(Chain<S> words) { |
46 | if (empty(words)) ret new State; |
47 | State s = prepareDescendant(new { |
48 | run { |
49 | print(first(words)); |
50 | addState(prepareDescendant(new State { |
51 | run { |
52 | dropFirst(words); |
53 | |
54 | doneWithSubroutine(); |
55 | } |
56 | }; |
57 | s.continuation = state -> { |
58 | print("World"); |
59 | }; |
60 | pm.addState(s); |
61 | } |
62 | } |
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: | 230 / 433 |
Version history: | 15 change(s) |
Referenced in: | [show references] |