core-logic

hifumi123 2023-11-14T07:14:43.533229Z

Is it possible to project on finite domain variables? My use case involves constructing a vector of integers where a certain integer does not appear more than n times. After much digging, I landed on using project like so

(defn counto [n coll]
  (let [fail? (some (fn [[_ count]]
                      (> count n))
                    (frequencies coll))]
    (if fail?
      l/fail
      l/succeed)))

(l/run* [x y z]
  (l/membero x (range 2))
  (l/membero y (range 2))
  (l/membero z (range 2))
  (l/project [x y z]
    (counto 2 [x y z])))
However, this means I cant use any finite domain variables. Am I missing something obvious? Ideally, I’d like to be able to do something like this:
(l/run* [q]
  (l/fresh [x y z]
    (l/== q [x y z])
    (fd/in x y z (fd/interval 0 1))
    (counto 2 q)))