core-logic

nitaai 2020-11-06T09:34:38.008Z

another question. are recursive anonymous goals possible in core.logic? i can’t get it working analogous to the regular fn.

nitaai 2020-11-06T11:57:28.008100Z

this workaround seems to work:

(defn packo [l1 l2]
  (letfn [(transfero [a b c d]
            (matche [a b c d]
              ([x [] [] [x]])
              ([x [y . ys] [y . ys] [x]] (!= x y))
              ([x [x . xs] ys [x . zs]] (transfero x xs ys zs))))]
    (matche [l1 l2]
      ([[] []])
      ([[x . xs] [z . zs]]
       (fresh [ys]
         (transfero x xs ys z)
         (packo ys zs))))))

nitaai 2020-11-06T11:59:12.008300Z

may be even more readable than fne etc on the other hand i think it should support naming the anonymous function and thus enable recursion, like the ordinary fn does. but maybe there is a reason why it doesn’t.