Skip to content

Commit

Permalink
Merge branch 'master' of github.com:clojure/core.logic
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Mar 13, 2013
2 parents 53cbfca + 8af0f45 commit 6b503b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/clojure/clojure/core/logic.clj
Expand Up @@ -2435,7 +2435,7 @@

clojure.lang.IPersistentMap
(disunify-terms [u v s cs]
(if (= (count u) (count v))
(if (and (map? v) (= (count u) (count v)))
(loop [ks (seq (keys u)) cs cs]
(if ks
(let [kf (first ks)
Expand Down
14 changes: 13 additions & 1 deletion src/main/clojure/clojure/core/logic/nominal.clj
Expand Up @@ -2,6 +2,7 @@
(:refer-clojure :exclude [== hash])
(:use [clojure.core.logic.protocols]
[clojure.core.logic :exclude [fresh] :as l])
(:require [clojure.pprint :as pp])
(:import [java.io Writer]
[clojure.core.logic LVar LCons]
[clojure.core.logic.protocols IBindable ITreeTerm]))
Expand Down Expand Up @@ -309,5 +310,16 @@
(instance? clojure.core.logic.nominal.Tie x))

(defmethod print-method Tie [x ^Writer writer]
(.write writer (str " [" (:binding-nom x) "] "))
(.write writer "[")
(print-method (:binding-nom x) writer)
(.write writer "] ")
(print-method (:body x) writer))

(defn- pprint-tie [x]
(pp/pprint-logical-block
(.write ^Writer *out* "[")
(pp/write-out (:binding-nom x))
(.write ^Writer *out* "] ")
(pp/write-out (:body x))))

(. pp/simple-dispatch addMethod Tie pprint-tie)
19 changes: 19 additions & 0 deletions src/test/clojure/clojure/core/logic/nominal/tests.clj
Expand Up @@ -502,3 +502,22 @@
(nom/hash a x)
(== q [x a]))))
'(([_0 a_1] :- a_1#_0)))))

(deftest test-logic-119-tie-disequality-1
(is (= (run* [q]
(nom/fresh [a]
(!= (nom/tie a a) 'foo)))
'(_0)))
(is (= (run* [q]
(nom/fresh [a]
(!= (nom/tie a a) (nom/tie a a))))
'()))
(is (= (run* [q]
(nom/fresh [a b]
(!= (nom/tie a a) (nom/tie a b))))
'(_0)))
(comment ;; this one will be tricky to get right.
(is (= (run* [q]
(nom/fresh [a b]
(!= (nom/tie a a) (nom/tie b b))))
'()))))
5 changes: 5 additions & 0 deletions src/test/clojure/clojure/core/logic/tests.clj
Expand Up @@ -1042,6 +1042,11 @@
(== x [1 w])
(== y [2 z])))
'(_0))))

(deftest test-logic-119-disequality-1
(is (= (run* [q]
(!= {1 2 3 4} 'foo))
'(_0))))
;; -----------------------------------------------------------------------------
;; tabled

Expand Down

0 comments on commit 6b503b0

Please sign in to comment.