Fork me on GitHub
#core-logic
<
2019-12-05
>
dpsutton02:12:09

if i have 6 logic variables, is there a way to ensure that 5 of them are distinct?

nitaai08:12:48

See distinct under https://github.com/clojure/core.logic/wiki/Features#clpfd I assume that’s what you are looking for.

yuhan09:12:36

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"

yuhan09:12:19

Can't think of an easy way to express that (besides macroexpanding all the permutations by brute force)

nitaai09:12:54

Oh yes, good point. I interpreted the question rather as “I know which 5 of the 6 lvars should be distinct”.

Stefan11:12:53

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?

eoliphant18:12:41

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')

hiredman19:12:41

you need l/== not ==

hiredman19:12:30

== is clojure core's numeric comparison function, l/== is core.logic's unification goal

dpsutton19:12:26

i hit that yesterday. the guide uses use clojure.core.logic so its easy to miss

eoliphant22:12:35

ah duh lol thanks guys