hi, I'm having some trouble with core.logic and function arities. I'm going through the reasoned schemer to learn and I've been trying to write some of my own relations as exercises. I wrote a simple implementation of concat
which worked fine, and I tried to convert it to a relation:
(defn dumb-concat [x y]
(cond
(empty? y) x
(empty? x) y
:else (recur (conj x (first y)) (rest y))))
(defn dumb-concato [x y out]
(l/conde
[(l/emptyo y) (l/== out x)]
[(l/emptyo x) (l/== out y)]
[l/succeed (l/fresh [f r c]
(l/conso f r y)
(l/conjo x f c)
(dumb-concato c r)
)]))
however, when I try and test this with (l/run 1 [q] (dumb-concato [0 1 2 3] [5 4 3] q))
it just says Wrong number of args (2) passed to: logic-practice.core/dumb-concato
what am I doing wrong? Or is this a bug?
because I'm certainly passing 3 arguments to it (the two vectors and the lvar)
(dumb-concato c r)
^ That line looks like the error to me.
Dum-concato is just a regular function, not a core.logic relation, so you can't use it like that
Err
Dumb-concat
What exactly a core.logic relation is kind of complicated, but a recursive definition would be something like, a core.logic relation is a function whose body is composed of core.logic relations
So dumb-concato would be a relation if it didn't call dumb-concat, but the body of dumb-concat is all non-relations (it is all functions from clojure.core)
The kind of problem you get with calling clojure.core functions in a logic program is they don't know how to deal with logic variables
And relations don't return values, but functions do
Oh
I misread your code though
What I read as a call to dumb-concat is actually a call to dumb-concato with the wrong number if arguments which is exactly what the error you got says
...how did I miss the obvious mistake
thanks guys
somehow managed to make that mistake almost every time