Skip to content

Commit f831acc

Browse files
David NolenDavid Nolen
authored andcommitted
everyo was a pseudo relation, rename to everyg. update bench.clj. add distincto relation which uses !=.
1 parent 67a937e commit f831acc

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/main/clojure/clojure/core/logic.clj

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,14 +2503,14 @@
25032503
(fresh [a]
25042504
(== (lcons a d) l)))
25052505

2506-
(defn everyo
2506+
(defn everyg
25072507
"A pseudo-relation that takes a coll and ensures that the goal g
25082508
succeeds on every element of the collection."
25092509
[g coll]
25102510
(if (seq coll)
25112511
(all
25122512
(g (first coll))
2513-
(everyo g (next coll)))
2513+
(everyg g (next coll)))
25142514
s#))
25152515

25162516
;; =============================================================================
@@ -3680,15 +3680,16 @@
36803680
((cgoal (!=c p)) a)))
36813681
a)))
36823682

3683-
(defn all-diffo [l]
3684-
(conde
3685-
[(== l ())]
3686-
[(fresh (a) (== l [a]))]
3687-
[(fresh (a ad dd)
3688-
(== l (llist a ad dd))
3689-
(!=c a ad)
3690-
(all-diffo (llist a dd))
3691-
(all-diffo (llist ad dd)))]))
3683+
(defne distincto
3684+
"A relation which guarantees no element of l will unify
3685+
with another element of l."
3686+
[l]
3687+
([()])
3688+
([[a]])
3689+
([[a b . r]]
3690+
(!= a b)
3691+
(distincto (lcons a r))
3692+
(distincto (lcons b r))))
36923693

36933694
(defne rembero
36943695
"A relation between l and o where is removed from
@@ -3697,4 +3698,4 @@
36973698
([_ [x . xs] xs])
36983699
([_ [y . ys] [y . zs]]
36993700
(!= y x)
3700-
(rembero x ys zs)))
3701+
(rembero x ys zs)))

src/main/clojure/clojure/core/logic/bench.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@
451451
sq2 [a3 a4 b3 b4]
452452
sq3 [c1 c2 d1 d2]
453453
sq4 [c3 c4 d3 d4]]
454-
(everyo distinctfd
454+
(everyg distinctfd
455455
[row1 row2 row3 row4
456456
col1 col2 col3 col4
457457
sq1 sq2 sq3 sq4])))))
@@ -503,11 +503,11 @@
503503
sqs (->squares rows)]
504504
(run-nc 1 [q]
505505
(== q vars)
506-
(everyo #(infd % (domain 1 2 3 4 5 6 7 8 9)) vars)
506+
(everyg #(infd % (domain 1 2 3 4 5 6 7 8 9)) vars)
507507
(init vars hints)
508-
(everyo distinctfd rows)
509-
(everyo distinctfd cols)
510-
(everyo distinctfd sqs))))
508+
(everyg distinctfd rows)
509+
(everyg distinctfd cols)
510+
(everyg distinctfd sqs))))
511511

512512
;; Helpers
513513

0 commit comments

Comments
 (0)