diff --git a/resources/public/docs/mw-engine/uberdoc.html b/resources/public/docs/mw-engine/uberdoc.html index 8a15e4b..f4ba5b6 100644 --- a/resources/public/docs/mw-engine/uberdoc.html +++ b/resources/public/docs/mw-engine/uberdoc.html @@ -3029,7 +3029,7 @@ net.brehaut.ClojureTools = (function (SH) { }; })(SyntaxHighlighter);
mw-engine0.1.0-SNAPSHOTCellular automaton world builder. -dependencies
| (this space intentionally left almost blank) | |||||||||||||||
Functions to transform a world and run rules. +dependencies
| (this space intentionally left almost blank) | |||||||||||||||
Functions to transform a world and run rules. | ||||||||||||||||
(ns mw-engine.core (:require [mw-engine.world :as world] @@ -3054,11 +3054,34 @@ See | ||||||||||||||||
Derive a cell from this cell of this world by applying these rules. + | ||||||||||||||||
Apply a single rule to a cell. What this is about is that I want to be able, + for debugging purposes, to tag a cell with the rule text of the rule which + fired (and especially so when an exception is thrown. So a rule may be either + an ifn, or a list (ifn source-text). This function deals with despatching + on those two possibilities. + | (defn apply-rule
+ ([cell world rule]
+ (cond
+ (ifn? rule) (apply-rule cell world rule nil)
+ (seq? rule) (let [[afn src] rule] (apply-rule cell world afn src))))
+ ;; {:afn afn :src src})))
+ ;; (apply-rule cell world (first rule) (first (rest rule)))))
+ ([cell world rule source]
+ (try
+ (let [result (apply rule (list cell world))]
+ (cond
+ (and result source) (merge result {:rule source})
+ true result))
+ (catch Exception e
+ (merge cell {:error (format "%s at generation %d when in state %s"
+ (.getMessage e)
+ (:generation cell)
+ (:state cell))
+ :error-rule source}))))) | |||||||||||||||
Derive a cell from this cell of this world by applying these rules. | (defn- apply-rules
[cell world rules]
(cond (empty? rules) cell
- true (let [result (apply (eval (first rules)) (list cell world))]
+ true (let [result (apply-rule cell world (first rules))]
(cond result result
true (apply-rules cell world (rest rules)))))) | |||||||||||||||
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 diff --git a/resources/public/docs/mw-parser/uberdoc.html b/resources/public/docs/mw-parser/uberdoc.html index 4b6e319..e7b0e9f 100644 --- a/resources/public/docs/mw-parser/uberdoc.html +++ b/resources/public/docs/mw-parser/uberdoc.html @@ -3053,7 +3053,7 @@ objective is to parse rules out of a block of text from a textarea function, and return the sequence of such functions. | (defn compile-string [string] - (map compile-rule (remove comment? (split string #"\n")))) | |||||||||||||||
Compile each non-comment line of the file indicated by this | ||||||||||||||||
Compile each non-comment line of the file indicated by this | (defn compile-file
[filename]
@@ -3393,18 +3393,26 @@ front of the sequence of tokens it returns nil.
true
(let [[left remainder] (parse-left-hand-side line)
[right junk] (parse-right-hand-side remainder)]
- ;; TODO: there shouldn't be any junk (should be null)
(cond
- (and left right (nil? junk))
+ ;; there should be a valide left hand side and a valid right hand side
+ ;; there shouldn't be anything left over (junk should be empty)
+ (and left right (empty? junk))
(list 'fn ['cell 'world] (list 'if left right)))))) | |||||||||||||||
Parse this return-tuple? is present and true, return
+ a list comprising the anonymous function compiled, and the function from
+ which it was compiled.
Throws an exception if parsing fails. | (defn compile-rule - [rule-text] - (do - (use 'mw-engine.utils) - (eval (parse-rule rule-text)))) | |||||||||||||||