core-logic

dpsutton 2019-12-05T02:52:09.031300Z

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

nitaai 2019-12-05T08:55:48.031400Z

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

yuhan 2019-12-06T09:23:36.034500Z

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"

yuhan 2019-12-06T09:25:19.034700Z

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

nitaai 2019-12-06T09:27:54.034900Z

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

Stefan 2019-12-09T11:18:53.035100Z

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?

eoliphant 2019-12-05T18:58:41.032700Z

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

2019-12-05T19:12:41.033Z

you need l/== not ==

2019-12-05T19:13:30.033700Z

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

dpsutton 2019-12-05T19:15:26.034100Z

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

eoliphant 2019-12-05T22:55:35.034400Z

ah duh lol thanks guys