I followed this example Insta Declarative DSL where we use Clara with instaparse to use a DSL and generate rules.
everything works for me as expected but one issue. I am not able to access the variable binding from the condition expressing in lhs and use it in rhs. For example, here is the code snippet from the above example.
(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))})})
now if I need to access the Customer name attribute from the lhs and use it in the insert operation in rhs, how would I modify the above transform function to achieve the same.
I need to write a transform function that should spit out a rule something similar to below.
(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))