Last active
June 15, 2016 04:09
-
-
Save whamtet/6d8430fe9b706990874303ec8708b756 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defonce persisted-frames (atom {})) | |
(defn persist [k v] | |
(swap! persisted-frames assoc k v) | |
v) | |
(defn split-until [f s] | |
(let [[a b] (split-with #(not (f %)) s)] | |
[(concat a (take 1 b)) (rest b)])) | |
(defmacro with-persists2 [df done todo] | |
(let [ | |
[to-persist todo] (split-until #(= '.persist %) todo) | |
persist-statement `(-> ~df ~@to-persist) | |
k (concat done to-persist) | |
] | |
(if (not= '.persist (last to-persist)) | |
persist-statement | |
`(let [ | |
persisted-frame# (or | |
(@persisted-frames '~k) | |
(persist '~k ~persist-statement)) | |
] | |
(with-persists2 persisted-frame# ~k ~todo))))) | |
(defmacro with-persists [df & statements] | |
`(with-persists2 ~df [~df] ~statements)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment