if i have 6 logic variables, is there a way to ensure that 5 of them are distinct?
See distinct
under https://github.com/clojure/core.logic/wiki/Features#clpfd
I assume that’s what you are looking for.
That's only for fd
logic variables though, I would think the question was equivalent to "at most one pair out of the 6 lvars can unify"
Can't think of an easy way to express that (besides macroexpanding all the permutations by brute force)
Oh yes, good point. I interpreted the question rather as “I know which 5 of the 6 lvars should be distinct”.
What about defining something like this: (untested)
(defnc 5-distinct [a b c d e f]
(= 5 (count (set [a b c d e f]))))
and then using that as a goal inside run
?hi I’m getting a weird error in the repl as I work through the core.logic getting started. I’m on jDK 11, wondering if it’s module related
(l/run* [q]
(l/fresh [a]
(l/membero a [1 2 3])
(l/membero q [3 4 5])
(== a q)))
Error printing return value (ClassCastException) at clojure.lang.Numbers/equiv (Numbers.java:238).
class clojure.core.logic.LVar cannot be cast to class java.lang.Number (clojure.core.logic.LVar is in unnamed module of loader clojure.lang.DynamicClassLoader @11da06db; java.lang.Number is in module java.base of loader 'bootstrap')
you need l/==
not ==
==
is clojure core's numeric comparison function, l/==
is core.logic's unification goal
i hit that yesterday. the guide uses use clojure.core.logic
so its easy to miss
ah duh lol thanks guys