This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-29
Channels
- # aws (2)
- # bangalore-clj (2)
- # beginners (36)
- # boot (10)
- # cider (9)
- # cljs-dev (19)
- # clojure (47)
- # clojure-russia (4)
- # clojure-spec (18)
- # clojure-uk (4)
- # clojurescript (71)
- # core-async (20)
- # core-logic (2)
- # css (3)
- # cursive (5)
- # data-science (15)
- # datomic (7)
- # emacs (13)
- # figwheel (4)
- # klipse (1)
- # luminus (5)
- # lumo (1)
- # off-topic (33)
- # re-frame (17)
- # shadow-cljs (1)
- # spacemacs (5)
- # specter (21)
- # unrepl (1)
- # vim (7)
I'm struggling with this simple relation, the results are incomplete, and I don't understand why. I'm beginning with core.logic I don't know if it is a bug or my bad understanding of it.
(require '[clojure.core.logic :as l])
(require '[clojure.core.logic.fd :as fd])
(defn zip+o [x y z]
(l/conde
[(l/== () x) (l/== () y) (l/== () z)]
[(l/fresh [fx rx fy ry fz rz]
(l/conso fx rx x)
(l/conso fy ry y)
(l/conso fz rz z)
(fd/in fx fy fz (fd/interval 10))
(fd/+ fx fy fz)
(zip+o rx ry rz))]))
; the same with defne macro
(comment
(l/defne zip+o [x y z]
([() () ()])
([[fx . rx]
[fy . ry]
[fz . rz]]
(fd/in fx fy fz (fd/interval 10))
(fd/+ fx fy fz)
(zip+o rx ry rz))))
(def expected-solutions
#{{:x [0 0] :y [1 1]}
{:x [0 1] :y [1 0]}
{:x [1 1] :y [0 0]}
{:x [1 0] :y [0 1]}})
(l/run* [q]
(l/fresh [x y]
(l/== q {:x x :y y})
(zip+o x y [1 1])))
;=> ({:x (1 0), :y (0 1)}
; {:x (0 0), :y (1 1)})