Fork me on GitHub
#core-logic
<
2020-01-27
>
Nico20:01:07

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

Nico20:01:23

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`

Nico20:01:29

what am I doing wrong? Or is this a bug?

Nico20:01:17

because I'm certainly passing 3 arguments to it (the two vectors and the lvar)

Jimmy Miller20:01:09

`(dumb-concato c r)`

Jimmy Miller20:01:55

^ That line looks like the error to me.

hiredman20:01:54

Dum-concato is just a regular function, not a core.logic relation, so you can't use it like that

hiredman20:01:22

Dumb-concat

hiredman20:01:07

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

hiredman20:01:53

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)

hiredman20:01:53

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

☝️ 4
hiredman20:01:30

And relations don't return values, but functions do

hiredman20:01:23

hiredman20:01:27

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

🙂 4
Nico21:01:01

...how did I miss the obvious mistake

Nico21:01:03

thanks guys

Nico21:01:08

somehow managed to make that mistake almost every time