core-logic

dominicm 2017-12-15T16:54:31.000463Z

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?

2017-12-15T17:09:10.000187Z

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

dominicm 2017-12-15T17:18:03.000002Z

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

2017-12-15T17:19:01.000367Z

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

dominicm 2017-12-15T17:24:32.000153Z

@hiredman Thanks, that led me to my solution.

dominicm 2017-12-15T17:38:39.000363Z

(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?

paulocuneo 2017-12-15T22:06:18.000125Z

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