core-logic

cjsauer 2018-02-24T21:51:07.000167Z

Hi all, I'm currently making my way through The Reasoned Schemer and have hit a bit of a block upon reaching chapter 4. I'm noticing that "the second commandment" produces logic functions that don't actually result in valid solutions. Especially in the case of rembero, e.g. frame 49. I skipped ahead a few pages to find the definition of surpriso, in which the book does admit that something strange is going on, but it wasn't followed with any kind of explanation as to a fix to this issue. Chapter 5 seems to continue right along without an explanation either... Anyone else encounter this?

cjsauer 2018-02-24T21:54:01.000061Z

Quick example to illustrate the point:

(defn rembero
  [x l out]
  (conde
   [(emptyo l) (== out '())]
   [(eq-firsto l x) (resto l out)]
   [s# (fresh [a d res]
         (conso a d l)
         (rembero x d res)
         (conso a res out))]))

(run* [r]
  (fresh [y z]
    (rembero y (list y 'd z 'e) (list y 'd 'e))
    (== (list y z) r)))
;; => ((d d)
;;     (d d)
;;     (_0 _0)
;;     (e e))

cjsauer 2018-02-24T21:54:36.000022Z

The last two solutions ((_0 _0) (e e)) don't satisfy the original constraint...

cjsauer 2018-02-24T22:00:11.000097Z

Ah, I found this thread https://groups.google.com/forum/#!topic/clojure/_z6-ZDiPh6A But no satisfying reply has yet been posted. @dnolen looks like maybe you came up against this issue as well (albeit years ago). Did you ever reach a satisfying conclusion?