Building a Business-Rule DSL with Clojure Macros for Equipment Inspection
The article shows how to build a DSL (domain-specific language)[1] for equipment inspection rules. From a conditional expression, the DSL generates a judgment function and a list of references that collect the evidence. Clojure macros read the expression as data, collect the references, and convert it into code that runs. Once a condition is written, the definitions needed for judgment and evidence collection are generated.
The example checks factory equipment inspection reports against an equipment master and maintenance standards, using five criteria: series, model number, operating temperature, next inspection date, and error response. Each criterion is judged as compliant or non-compliant, and the result includes the input items and values used as evidence. In the sample report, only the temperature fails, with a reading of 82 against an upper limit of 75 degrees.
The authors first show a DSL they built in Python, where each input needs a separate reference object and identifier. In Clojure, a macro named defcriteria takes a condition such as (report :稼働温度) and generates both the reference list and the judgment function from that one expression. The article then explains Clojure syntax, quoting, and how macros work, using an unless example. It plans to extend the temperature example to all five criteria.
Sources
-
JPZenn JA
Clojureのマクロによるメタプログラミングで業務ルールのDSLを作る
Terms
- macro — A Clojure feature that receives code as data before it runs and rewrites it into other code.






