NewsCrawler.org

Building a Business-Rule DSL with Clojure Macros for Equipment Inspection

Clojureのマクロによるメタプログラミングで業務ルールのDSLを作る
点検報告と機器マスタを5つのルールで判定し、温度だけが不適合となる例
入力への参照と固定値をwhenに渡し、thenで適合を結び付け、Criterionでそれ以外を不適合にするPython DSLの定義
条件式から参照一覧と判定関数を作り、点検報告の温度82を上限75と比較して不適合と根拠を返すClojure DSLの全体像
Image: zenn.dev

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.

Read the original zenn.dev

Sources

  • Zenn JA

    Clojureのマクロによるメタプログラミングで業務ルールのDSLを作る

    17 likes1 bookmark0 comments

Terms

  1. macro — A Clojure feature that receives code as data before it runs and rewrites it into other code.

Published: First seen: Читать по-русски

Open as a page