Mercurial > vba-clojure
comparison clojure/com/aurellem/run/title.clj @ 313:8e63b0bb8ea3
major refactoring; made (walk) more robust
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 02 Apr 2012 10:58:16 -0500 |
parents | c7b002525041 |
children | 9a4d3f801c89 |
comparison
equal
deleted
inserted
replaced
305:7998b1cf18cf | 313:8e63b0bb8ea3 |
---|---|
1 (ns com.aurellem.run.title | 1 (ns com.aurellem.run.title |
2 (:use (com.aurellem.gb gb-driver vbm))) | 2 (:use (com.aurellem.gb gb-driver vbm))) |
3 | 3 |
4 (defn first-difference [base alt summary root] | |
5 (loop [branch-point root | |
6 actions []] | |
7 (let [base-branch (step branch-point base) | |
8 base-val (summary base-branch) | |
9 alt-branch (step branch-point alt) | |
10 alt-val (summary alt-branch)] | |
11 (if (not= base-val alt-val) | |
12 [(conj actions alt) alt-branch] | |
13 (recur base-branch (conj actions base)))))) | |
14 | |
15 (defn advance | |
16 ([base alt summary [commands state]] | |
17 (let [[c s] (first-difference base alt summary state)] | |
18 [(concat commands c) s])) | |
19 ([base alt [commands state]] | |
20 (advance base alt AF [commands state])) | |
21 ([alt [commands state]] | |
22 (advance [] alt [commands state]))) | |
23 | |
24 (defn scroll-text | |
25 ([script] | |
26 (advance [:b] [:a :b] script)) | |
27 ([n script] | |
28 (reduce (fn [script _] | |
29 (scroll-text script)) | |
30 script | |
31 (range n)))) | |
32 | 4 |
33 (defn start [] [[] (root)]) | 5 (defn start [] [[] (root)]) |
34 | 6 |
35 (defn-memo title | 7 (defn-memo title |
36 ([] (title (start))) | 8 ([] (title (start))) |