This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-27
Channels
- # beginners (3)
- # boot (8)
- # cljs-dev (10)
- # clojure (87)
- # clojure-art (6)
- # clojure-dev (13)
- # clojure-japan (8)
- # clojure-russia (60)
- # clojure-sg (2)
- # clojurescript (126)
- # clojurewerkz (1)
- # core-logic (10)
- # cursive (6)
- # datomic (30)
- # editors (10)
- # ldnclj (7)
- # off-topic (114)
- # onyx (7)
- # re-frame (7)
- # reagent (37)
(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])))
For example, the fourth result is already subsumed by the third, and the 8th and the last result can never become true, no?
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?
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
@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*.
FWIW, I don't need to have relations on lists of characters, so that representation could be reserved for strings.