Clojure 使用instaparse动态生成clara规则时遇到问题
我遵循了这个示例,我们使用Clara和instaparse来使用DSL并生成规则 除了一个问题外,一切都如我所料。我无法从lhs中表示的条件访问变量绑定并在rhs中使用它。 例如,下面是上面示例中的代码片段Clojure 使用instaparse动态生成clara规则时遇到问题,clojure,rule-engine,clojure-java-interop,plumatic-schema,instaparse,Clojure,Rule Engine,Clojure Java Interop,Plumatic Schema,Instaparse,我遵循了这个示例,我们使用Clara和instaparse来使用DSL并生成规则 除了一个问题外,一切都如我所料。我无法从lhs中表示的条件访问变量绑定并在rhs中使用它。 例如,下面是上面示例中的代码片段 (def shopping-transforms {:NUMBER #(Integer/parseInt %) :OPERATOR operators :FACTTYPE fact-types :CONDITION (fn [fact-type field operat
(def shopping-transforms
{:NUMBER #(Integer/parseInt %)
:OPERATOR operators
:FACTTYPE fact-types
:CONDITION (fn [fact-type field operator value]
{:type fact-type
:constraints [(list operator (symbol field) value)]})
;; Convert promotion strings to keywords.
:PROMOTIONTYPE keyword
:DISCOUNT (fn [name percent & conditions]
{:name name
:lhs conditions
:rhs `(insert! (->Discount ~name ~percent))})
:PROMOTION (fn [name promotion-type & conditions]
{:name name
:lhs conditions
:rhs `(insert! (->Promotion ~name ~promotion-type))})})
现在,如果我需要从lhs访问Customer name属性,并在rhs中的插入操作中使用它,我将如何修改上述转换函数以实现相同的功能
我需要编写一个转换函数,该函数应该给出一个类似于下面的规则
(defrule temperature-alert
"Issue a temperature alert. This rule joins the current temperature with the location
and gathers additional information to fire an alert with context."
[CurrentTemperature (> value high-threshold)
(= ?location-id location)
(= ?value value)]
[Location (= ?location-id id)
(= ?sector sector)]
=>
(alert-temperature! ?value ?location-id ?sector))