Mercurial > vba-clojure
view clojure/com/aurellem/title2.clj @ 85:3f4fdd270059
more progress with the title
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 10 Mar 2012 00:32:11 -0600 |
parents | 26f002f2868c |
children | 9864032ef3c8 |
line wrap: on
line source
1 (ns com.aurellem.title22 (:use (com.aurellem gb-funs vbm)))4 (defn first-difference [base alt summary root]5 (loop [branch-point root6 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))))))15 (defn advance16 ([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])))24 (def scroll-text (partial advance [:b] [:a :b]))26 (defn title []27 (->> [[] (root)]28 (advance [] [:a])29 (advance [] [:start])30 (advance [] [:a])31 (advance [] [:start])))33 (def title-end (second (title)))35 (defn oak []36 (->> [[] title-end]37 scroll-text38 scroll-text39 scroll-text40 scroll-text41 scroll-text42 scroll-text43 scroll-text44 scroll-text45 scroll-text46 scroll-text47 scroll-text48 scroll-text49 scroll-text50 (advance [] [:a])))52 ;; looks like it might need a monad here if this pattern continues54 (def oak-end (second (oak)))56 (defn name-entry []57 (->> [[] oak-end]58 (advance [] [:r] DE)59 ((fn [[moves state]]60 (play-moves61 state62 [[]63 [:r] [] [:r] [] [:r] [] [:r] []64 [:r] [] [:r] [] [:r] [] [:d] [:a]65 [:l] [] [:l] [] [:l] [] [:l] []66 [:l] [] [:l] [:a] [] [:r] [:a]67 [:r] [] [:r] [] [:r] [] [:r] []68 [:r] [] [:d] [] [:d] [] [:d] [:a]69 ])))))