Created
June 1, 2012 08:58
-
-
Save rrees/2850527 to your computer and use it in GitHub Desktop.
Core logic example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns euroclojure.logic | |
(:use [clojure.core.logic])) | |
(defn query [] | |
(run 1 [q] | |
(membero q [1 2 3]))) | |
;; 1 | |
(defn query-all [] | |
(run* [q] | |
(membero q [1 2 3]))) | |
;; (1 2 3) | |
(defn query-intersect [] | |
(run* [q] | |
(membero q [2 4 6 8]) | |
(membero q [0 1 4 8]))) | |
;; (4 8) | |
(defn transistive [] | |
(run* [q] | |
(fresh [a b] | |
(membero b [ 2 3 4 7 13]) | |
(== q a) | |
(== a b) | |
(membero a [2 7 9])))) | |
;; (2 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment