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
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
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"}
:codox {:metadata {:doc "**TODO**: write docs"
:doc/format :markdown}

View file

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