core-logic

tsdh 2015-07-27T09:04:22.000006Z

Can someone enlighten me with some ccl result?

tsdh 2015-07-27T09:04:41.000007Z

(run* [q]
  (fresh [a b c]
    (== q [a b c])
    (membero 1 q)
    (membero 3 q)
    (conde
     [(conso 1 [b c] q)]
     [(conjo [a b] 3 q)])))
;; ([1 3 _0]
;;  [1 3 3]
;;  [1 _0 3]
;;  ([1 _0 3] :- (clojure.core.logic/conjo [<lvar:a__21997> <lvar:b__21998>] 3 [1 _0 3]))
;;  [3 1 3]
;;  [1 1 3]
;;  ([_0 1 3] :- (clojure.core.logic/conjo [<lvar:a__21997> <lvar:b__21998>] 3 [_0 1 3]))
;;  ([3 _0 1] :- (clojure.core.logic/conjo [<lvar:a__21997> <lvar:b__21998>] 3 [3 _0 1]))
;;  [1 3 1]
;;  ([_0 3 1] :- (clojure.core.logic/conjo [<lvar:a__21997> <lvar:b__21998>] 3 [_0 3 1])))

tsdh 2015-07-27T09:05:41.000008Z

For example, the fourth result is already subsumed by the third, and the 8th and the last result can never become true, no?

tsdh 2015-07-27T10:52:00.000009Z

Another thing: Is is somehow possible to do logic programming with strings? One could use conso, resto, and appendo with lists of characters of course, but can this be done somewhat transparently so that I could define (stro a b ab) which is like appendo but translates from/to lists of characters as needed?

jballanc 2015-07-27T15:57:58.000011Z

tsdh: to answer your second question first, you can always write your own string-based methods either using the core.logic primatives, or just deconstructing/reconstructing the string and using conso and friends

tsdh 2015-07-27T17:19:57.000012Z

@jballanc: looking at how complicated firsto and friends are with their LCons deftype etc, reusing that seems like the way to go. However, I just wondered if I could get the conversion from/to lists of characters transparently/implicitly rather than doing it from outside of run*.

tsdh 2015-07-27T17:30:38.000013Z

FWIW, I don't need to have relations on lists of characters, so that representation could be reserved for strings.

jballanc 2015-07-27T18:59:07.000014Z

hmm…I think it should be possible to pass strings around…have to think about it

jballanc 2015-07-27T19:00:45.000015Z

oh, and about your first question…not sure but I think what’s happening is: 1. for the 4th result, you’re swapping a and b as to which is 1 and which is unbound (`_0`) 2. for the 8th result, one of your fresh vars in the conjo is empty…I think

jballanc 2015-07-27T19:00:55.000016Z

would have to double-check that last one, though