一、Core.logic的基本语法:
(run* [logic-variable] logic-expressions) ;;或者 (run 1 [logic-variable] logic-expressions)
二、三个核心操作符号:fresh, ==, conde。
其实用几段最简单的代码就可以明白。
user=>(run* [q] (fresh [a b ] (== a 1) (== b 2) (== q [a b]))) ([1 2]) user=>(run* [q] (fresh [a b] (conde [(== 1 a)] [(== 2 b)]) (== q a) (== q b))) (1 2)
其中fresh就相当于let,定义局部变量。==就是逻辑相等。conde和cond有点像,用一段伪代码表示就是
(run* [q] (OR [goal1 AND goal2 AND ...] ...))
三、来几个高级的goal:conso,resto,membero。其中结尾带o,a,u,e就是一种命名规范而已,为了和clojure自带的cons,rest,member区分开来。
user=> (run* [q] (membero q [1 2 3])) (1 2 3) user=> (run* [q] (resto q [1 2 3])) ((_0 1 2 3)) user=> (run* [q] (conso 1 [2 3] q)) ((1 2 3))