Almost working; rule editor doesn't save.
This commit is contained in:
parent
5bfddf2e28
commit
76ab08534c
|
@ -26,13 +26,21 @@
|
|||
;; rules are applied in turn until one matches. Once one rule has matched no
|
||||
;; further rules can be applied.
|
||||
|
||||
(defn- transform-cell
|
||||
(defn- apply-rules
|
||||
"Derive a cell from this cell of this world by applying these rules."
|
||||
[cell world rules]
|
||||
(cond (empty? rules) cell
|
||||
true (let [result (apply (eval (first rules)) (list cell world))]
|
||||
(cond result result
|
||||
true (transform-cell cell world (rest rules))))))
|
||||
true (apply-rules cell world (rest rules))))))
|
||||
|
||||
(defn- transform-cell
|
||||
"Derive a cell from this cell of this world by applying these rules. If an
|
||||
exception is thrown, cache its message on the cell and set state to error"
|
||||
[cell world rules]
|
||||
(try
|
||||
(apply-rules cell world rules)
|
||||
(catch Exception e (merge {:state :error :error (.getMessage e)} cell))))
|
||||
|
||||
(defn- transform-world-row
|
||||
"Return a row derived from this row of this world by applying these rules to each cell."
|
||||
|
|
Loading…
Reference in a new issue