Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

LOGIC-75: needed -force-ans implementations for clojure.lang.IPersist…

…entMaps as well as LCons
  • Loading branch information...
commit c96402f3e60b1118446b3e681d98e444e4ce417d 1 parent 2ee0f1b
David Nolen authored
View
20 src/main/clojure/clojure/core/logic.clj
@@ -3135,7 +3135,25 @@
s#))]
(loop (seq v))))
- ;; clojure.lang.IPersistentMap
+ clojure.lang.IPersistentMap
+ (-force-ans [v x]
+ (letfn [(loop [ys]
+ (if ys
+ (all
+ (force-ans (val (first ys)))
+ (loop (next ys)))
+ s#))]
+ (loop (seq v))))
+
+ clojure.core.logic.LCons
+ (-force-ans [v x]
+ (letfn [(loop [ys]
+ (all
+ (force-ans (lfirst ys))
+ (if (lcons? (lnext ys))
+ (loop (lnext ys))
+ s#)))]
+ (loop v)))
FiniteDomain
(-force-ans [v x]
View
14 src/test/clojure/clojure/core/logic/tests.clj
@@ -1259,6 +1259,20 @@
(== {:a 1} (partial-map {:a q})))
'(1))))
+(deftest test-75-map-sum-maps-lcons
+ (is (= (into #{}
+ (run* [q]
+ (fresh [x]
+ (infd x (interval 1 3))
+ (== q {:foo x}))))
+ (into #{} '({:foo 1} {:foo 2} {:foo 3}))))
+ (is (= (into #{}
+ (run* [q]
+ (fresh [x y]
+ (infd x (interval 1 3))
+ (== q (lcons x y)))))
+ (into #{} [(lcons 1 '_.0) (lcons 2 '_.0) (lcons 3 '_.0)]))))
+
;; =============================================================================
;; cKanren
Please sign in to comment.
Something went wrong with that request. Please try again.