From ff6bbad14cef9cb54c6200eda1ae6d70b8f1b1a1 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Wed, 19 Jul 2023 20:35:19 +0100 Subject: [PATCH] Major overhaul of rule metadata, so upversioned to 0.3.0 Many tests do not pass at this stage --- project.clj | 2 +- src/cljc/mw_engine/core.clj | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/project.clj b/project.clj index aae50c2..f3885f4 100644 --- a/project.clj +++ b/project.clj @@ -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} diff --git a/src/cljc/mw_engine/core.clj b/src/cljc/mw_engine/core.clj index 5c95e58..ed7c48f 100644 --- a/src/cljc/mw_engine/core.clj +++ b/src/cljc/mw_engine/core.clj @@ -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)] - (when result - (merge result {:rule src - :lisp lisp}))))) + (let [result (apply rule (list cell world))] + (when result + (merge result (meta rule))))) (defn- apply-rules "Derive a cell from this `cell` of this `world` by applying these `rules`."