Fork me on GitHub
#core-logic
<
2017-12-15
>
dominicm16:12:31

I'm using core logic to get a list of things, and infer properties about them. No answers (`nil`) is a perfectly valid answer, but I don't want to throw away an item which doesn't have an answer for a particular question. How can I do this?

hiredman17:12:10

user=> (l/run* [q] (l/== q nil))
(nil)
user=>

dominicm17:12:03

@hiredman I've potentially already got an answer for my question though, so I can't do that.

hiredman17:12:01

user=> (l/run* [q] (l/conde [(l/== q nil)] [(l/!= q nil)]))
(nil (_0 :- (!= (_0 nil))))
user=>

dominicm17:12:32

@hiredman Thanks, that led me to my solution.

dominicm17:12:39

(l/run*
    [x q]
    (l/== x 10)
    (fn [a]
      (l/to-stream [])))
I have a case where this could happen. How can I detect that q hasn't been bound and mark it as nil, so that I still get an answer about x?

paulocuneo22:12:18

do you really really really really need to check if x is "fresh" (i guess thats what you mean with unbound)? ;; Following code loses relational properties (conde [(lvaro q) ;; q is fresh... ] [(nonlvaro q) ;; q is not fresh ])