Skip to content

Commit ee4ae2e

Browse files
committed
Implement rembero2 to resolve discrepancy between book and clojure.logic
1 parent 30401e6 commit ee4ae2e

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

mini-kanren/src/mini_kanren/utils.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@
167167
(memo x d out)))))
168168

169169
;;; Frame 4-24
170-
#_(defn rembero
170+
(defn rembero2
171171
"Succeeds when out equals l with the first occurrence of x removed."
172172
[x l out]
173173
(conde
174174
((emptyo l) (== () out))
175175
((eq-caro l x) (resto l out))
176176
(s# (fresh [a d res]
177177
(resto l d)
178-
(rembero x d res)
178+
(rembero2 x d res)
179179
(firsto l a)
180180
(conso a res out)
181181
))))

mini-kanren/test/mini_kanren/core_test.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,4 +721,14 @@
721721
(fresh [y z]
722722
(rembero y (list y 'd z 'e) (list y 'd 'e))
723723
(== (list y z) r)))))
724+
725+
;; Resolve this mystery by implementing our own rembero, called
726+
;; rembero2, in the file utils.clj, according to the guidelines in
727+
;; Frame 4-24. TODO: examine the implementation of "rember" in
728+
;; clojure.core/logic.
729+
(test/is (=
730+
'([(d d) d d] [(d d) d d] [(_0 _0) _0 _0] [(e e) e e]
731+
) (run* [r y z]
732+
(rembero2 y (list y 'd z 'e) (list y 'd 'e))
733+
(== (list y z) r))))
724734
)

0 commit comments

Comments
 (0)