// Logic thread for "for any * holds *" static class LThread2 { IEngine engine; new L<Lisp> statements; new SNLMatches m; // current variable assignments int opIdx; new L<Lisp> output; L<S> log; new L<Iterator<Boolean>> iterators; new L<Integer> states; *(Lisp code) { this(null, code); } *(IEngine *engine, Lisp code) { assertTrue(snlMatch2("for < any < For < holds < Holds", code, m)); addIterator(getIterator("For")); } void addIterator(Iterator<Boolean> it) { if (it != null) { iterators.add(it); } // returns false if done boolean step() { while true { if (empty(iterators)) ret false; Iterator<Boolean it = last(iterators); if (it.next()) ret true; popLast(iterators); } } Iterator<Boolean> getIterator(S var) { Lisp term = snlApply(m.get(var), m); new SNLMatches m2; if (!snlMatch2("X < in < Y", m2)) ret null; final L<Lisp> list = snlParseList(Y); int state = -1; ret new Iterator<Boolean>() { int i = 0; public boolean hasNext() { ret i < l(list); ] public Boolean next() { m.set(m2.str("X"), list.get(i++)); ret true; } public void remove() {} }; } void say(Lisp b) { output.add(snlApply(b, m.map)); } }
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: | 803 / 730 | 
| Referenced in: | [show references] |