Fork me on GitHub
#core-logic
<
2020-11-06
>
nitaai09:11:38

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

nitaai11:11:28

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

nitaai11:11:12

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.