Browse files

Made it possible to define facts on a relation defined in a different…

… namespace by keeping the original namespace of the relation into its metadata.
  • Loading branch information...
1 parent df64d96 commit eb6dfda6ecc3604a987f479cd42696d4d8ad685a @budu budu committed with swannodette Nov 13, 2011
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/main/clojure/clojure/core/logic.clj
View
13 src/main/clojure/clojure/core/logic.clj
@@ -1410,9 +1410,15 @@
arity-excs (fn [n] `(arity-exc-helper '~name ~n))]
(if (seq args)
`(do
- (def ~name (~'clojure.core.logic.Rel. '~name (atom {}) nil ~@(map arity-excs r)))
+ (def ~name
+ (.withMeta
+ (~'clojure.core.logic.Rel. '~name (atom {}) nil ~@(map arity-excs r))
+ {:ns ~'*ns*}))
(extend-rel ~name ~@args))
- `(def ~name (~'clojure.core.logic.Rel. '~name (atom {}) nil ~@(map arity-excs r))))))
+ `(def ~name
+ (.withMeta
+ (~'clojure.core.logic.Rel. '~name (atom {}) nil ~@(map arity-excs r))
+ {:ns ~'*ns*})))))
(defmacro def-apply-to-helper [n]
(let [r (range 1 (clojure.core/inc n))
@@ -1522,7 +1528,8 @@
represents a fact tuple, all with the same number of elements."
([rel [f :as tuples]] (facts rel (count f) tuples))
([^Rel rel arity tuples]
- (let [rel-set (var-get (resolve (set-sym (.name rel) arity)))
+ (let [rel-ns (:ns (meta rel))
+ rel-set (var-get (ns-resolve rel-ns (set-sym (.name rel) arity)))
tuples (map vec tuples)]
(swap! rel-set (fn [s] (into s tuples)))
(let [indexes (indexes-for rel arity)]

0 comments on commit eb6dfda

Please sign in to comment.