Major overhaul of rule metadata, so upversioned to 0.3.0

Many tests do not pass at this stage
This commit is contained in:
Simon Brooke 2023-07-19 20:35:19 +01:00
parent 321e6edd9a
commit ac25969f90
3 changed files with 15 additions and 12 deletions

View file

@ -13,6 +13,13 @@ You can see MicroWorld in action [here](http://www.journeyman.cc/microworld/) -
but please don't be mean to my poor little server. If you want to run big maps but please don't be mean to my poor little server. If you want to run big maps
or complex rule-sets, please run it on your own machines. or complex rule-sets, please run it on your own machines.
### Version compatibility
There are substantial changes in how rule functions are evaluated between 0.1.x
versions of MicroWorld libraries and 0.3.x versions. In particular, in 0.3.x
metadata is held on rule functions which is essential to the functioning of the
engine. Consequently, you cannot mix 0.1.x and 0.3.x libraries: it will not work.
## Usage ## Usage
Primary entry points are make-world and run-world, both in mw-engine.core. See Primary entry points are make-world and run-world, both in mw-engine.core. See

View file

@ -1,4 +1,4 @@
(defproject mw-engine "0.2.0-SNAPSHOT" (defproject mw-engine "0.3.0-SNAPSHOT"
:cloverage {:output "docs/cloverage"} :cloverage {:output "docs/cloverage"}
:codox {:metadata {:doc "**TODO**: write docs" :codox {:metadata {:doc "**TODO**: write docs"
:doc/format :markdown} :doc/format :markdown}

View file

@ -53,18 +53,14 @@
(defn apply-rule (defn apply-rule
"Apply a single `rule` to a `cell`. What this is about is that I want to be able, "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 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 fired (and especially so when an exception is thrown). "
an ifn, or a list (ifn source-text). This function deals with despatching ;; as of version 0-3-0, metadata for rules is now passed around on the metadata
on those two possibilities. `world` is also passed in in order to be able ;; of the rule function itself. Yes, I know, this is obvious; but I'll confess
to access neighbours." ;; I didn't think of it before.
[world cell rule] [world cell rule]
(cond (let [result (apply rule (list cell world))]
(ifn? rule) (apply rule (list cell world)) (when result
(seq? rule) (let [[afn src lisp] rule (merge result (meta rule)))))
result (apply-rule world cell afn)]
(when result
(merge result {:rule src
:lisp lisp})))))
(defn- apply-rules (defn- apply-rules
"Derive a cell from this `cell` of this `world` by applying these `rules`." "Derive a cell from this `cell` of this `world` by applying these `rules`."