1 | // Logic thread for "for any * holds *" |
2 | |
3 | static class LThread2 {
|
4 | IEngine engine; |
5 | new L<Lisp> statements; |
6 | |
7 | new SNLMatches m; // current variable assignments |
8 | int opIdx; |
9 | new L<Lisp> output; |
10 | L<S> log; |
11 | new L<Iterator<Boolean>> iterators; |
12 | new L<Integer> states; |
13 | |
14 | *(Lisp code) {
|
15 | this(null, code); |
16 | } |
17 | |
18 | *(IEngine *engine, Lisp code) {
|
19 | assertTrue(snlMatch2("for < any < For < holds < Holds", code, m));
|
20 | addIterator(getIterator("For"));
|
21 | } |
22 | |
23 | void addIterator(Iterator<Boolean> it) {
|
24 | if (it != null) {
|
25 | iterators.add(it); |
26 | } |
27 | |
28 | // returns false if done |
29 | boolean step() {
|
30 | while true {
|
31 | if (empty(iterators)) ret false; |
32 | |
33 | Iterator<Boolean it = last(iterators); |
34 | if (it.next()) |
35 | ret true; |
36 | |
37 | popLast(iterators); |
38 | } |
39 | } |
40 | |
41 | Iterator<Boolean> getIterator(S var) {
|
42 | Lisp term = snlApply(m.get(var), m); |
43 | new SNLMatches m2; |
44 | if (!snlMatch2("X < in < Y", m2))
|
45 | ret null; |
46 | final L<Lisp> list = snlParseList(Y); |
47 | int state = -1; |
48 | |
49 | ret new Iterator<Boolean>() {
|
50 | int i = 0; |
51 | |
52 | public boolean hasNext() {
|
53 | ret i < l(list); |
54 | ] |
55 | |
56 | public Boolean next() {
|
57 | m.set(m2.str("X"), list.get(i++));
|
58 | ret true; |
59 | } |
60 | |
61 | public void remove() {}
|
62 | }; |
63 | } |
64 | |
65 | void say(Lisp b) {
|
66 | output.add(snlApply(b, m.map)); |
67 | } |
68 | } |
Began life as a copy of #1002752
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1002810 |
| Snippet name: | LThread with backtracking (dev.) |
| Eternal ID of this version: | #1002810/1 |
| Text MD5: | 6e0a8aaf97852693cd676c339e601d58 |
| Author: | stefan |
| Category: | eleu / nl |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-02-26 02:14:50 |
| Source code size: | 1442 bytes / 68 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 805 / 733 |
| Referenced in: | [show references] |