Skip to content

Commit 2a715fe

Browse files
committed
Add not-pathc and get-c constraint functions
1 parent a40e558 commit 2a715fe

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/palletops/locos.clj

+7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@
131131
[name & rules]
132132
`(def ~name (rules->logic-terms ~(vec (quote-rules rules)))))
133133

134+
;; guarantee that a path of keys does not occur in map x
135+
(defc not-pathc [x path]
136+
(= (get-in x path ::not-found) ::not-found))
137+
138+
(defc get-c [x s]
139+
(not= (get s x ::not-found) ::not-found))
140+
134141
(defn matching-productions
135142
"Takes an expression, and applies rules to it, returning a sequence
136143
of valid productions."

test/palletops/locos_test.clj

+7
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,10 @@
6969
(is (= {:item :b} (apply-productions {:item :b} rules)))
7070
(is (= {:x 1} (apply-productions {} rules)))
7171
(is (= {:x 2 :a 1} (apply-productions {:a 1} rules)))))
72+
73+
(deftest guard-test
74+
(let [rules (rules [{:m ?a} {:x 1} (not-pathc ?a [:c :d])])]
75+
(let [r (apply-rule-productions {:m {}} rules)]
76+
(is (= {:m {} :x 1} r)))
77+
(let [r (apply-rule-productions {:m {:c {:d 1}}} rules)]
78+
(is (= {:m {:c {:d 1}}} r)))))

0 commit comments

Comments
 (0)