Skip to content

Commit

Permalink
LOGIC-64: Adds sugar syntax for inequalities in finite domains
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonbloom authored and David Nolen committed Oct 27, 2012
1 parent 3120142 commit 423639c
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/main/clojure/clojure/core/logic.clj
Expand Up @@ -3223,6 +3223,18 @@
(<=fd u v)
(!=fd u v)))

(defn >fd
"A finite domain constraint. u must be greater than v. u and v
must eventually be given domains if vars."
[u v]
(<=fd v u))

(defn >=fd
"A finite domain constraint. u must be greater than or equal to v.
u and v must eventually be given domains if vars."
[u v]
(<fd v u))

;; NOTE: we could put logic right back in but then we're managing
;; the constraint in the body again which were trying to get
;; away from
Expand Down Expand Up @@ -3480,14 +3492,19 @@
;; -----------------------------------------------------------------------------
;; FD Equation Sugar

(def binops '#{+ - * / =})

(def binops->fd
'{+ clojure.core.logic/+fd
- clojure.core.logic/-fd
* clojure.core.logic/*fd
/ clojure.core.logic/quotfd
= clojure.core.logic/==})
'{+ clojure.core.logic/+fd
- clojure.core.logic/-fd
* clojure.core.logic/*fd
/ clojure.core.logic/quotfd
= clojure.core.logic/==
!= clojure.core.logic/!=fd
<= clojure.core.logic/<=fd
< clojure.core.logic/<fd
>= clojure.core.logic/>=fd
> clojure.core.logic/>fd})

(def binops (set (keys binops->fd)))

(defn expand [form]
(if (seq? form)
Expand Down

0 comments on commit 423639c

Please sign in to comment.