Skip to content

Commit af92cdb

Browse files
author
Paula Gearon
committed
Added better assertion checking on data types
1 parent a93096d commit af92cdb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/naga/rules.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
[x]
2020
(and (symbol? x) (= \% (first (name x)))))
2121

22+
(defn- vars [constraint]
23+
(if (list? constraint)
24+
(filter st/vartest? (rest constraint))
25+
(st/vars constraint)))
26+
2227
(defn mark-unbound
2328
"Convert a head to use fresh vars for any vars that are unbound.
2429
Scans the vars in the body to identify which vars are unbound."
@@ -37,6 +42,8 @@
3742
"Body must be a sequence of constraints")
3843
(assert (and (sequential? head) (or (empty? head) (every? sequential? head)))
3944
"Head must be a sequence of constraints")
45+
(assert (every? (complement fresh-var?) (mapcat vars body))
46+
"Fresh vars are not allowed in a body")
4047
(st/new-rule (mark-unbound head body) body name)))
4148

4249
(s/defn named-rule :- Rule

0 commit comments

Comments
 (0)