我们如何更新 clara 规则中的事实? (clojure)

问题描述 投票:0回答:0
(ns clara.rules.test
  (:require [clara.rules :refer :all]))

(defrecord Users [#^ints user-ids])
(defrecord UserData [user-id dob age]

(defrule rule-1
 [?ud <- UserData (> age 20)]
 [?u <- Users]
 =>
 ((retract ?u)
  (insert! (->Users (conj (:user-ids ?u) (:user-id ?ud)))))

(defrule rule-2
 [?ud <- UserData (some-condition)]
 [?u <- Users]
 =>
 ((retract ?u)
  (insert! (->Users (conj (:user-ids ?u) (:user-id ?ud)))))

(defn run-rules
  [user-data]
  (let [res (-> (mk-session 'clara.rules.test)
                (insert (->UserData (:user-id user-data) (:dob user-data) (:age user-data))
                        (->Users []))
                (fire-rules))])

我正在尝试将用户 ID 附加到

Users
defrecord 或更新列表。我在会话中插入一个空列表作为用户事实。我写的规则的动作不会起作用,但我想做类似的事情。

我想知道是否有办法更新现有事实或删除并在规则的 rhs 上插入新的更新事实。

提前致谢

functional-programming clojure rules rule-engine
© www.soinside.com 2019 - 2024. All rights reserved.