Created
November 25, 2011 00:36
-
-
Save roman/1392568 to your computer and use it in GitHub Desktop.
Usage of clojure.core.logic
This file contains 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 logical.core | |
(:use [clojure.core.logic | |
:only [ | |
defrel fact fresh to-stream unify all | |
]])) | |
(defrel man p) | |
(fact man "adam") | |
(fact man "peter") | |
(fact man "paul") | |
(defrel woman p) | |
(fact woman "marry") | |
(fact woman "eve") | |
(defrel parent p c) | |
(fact parent "adam" "peter") | |
(fact parent "eve" "peter") | |
(fact parent "adam" "paul") | |
(fact parent "marry" "paul") | |
(defn father [f c] | |
(all | |
(parent f c) | |
(man f))) | |
; (use 'logical.core) | |
; (use '[clojure.core.logic :rename { == unify }]) | |
; (run* [q] (fresh [f c] (father f c) (unify q f))) | |
; -> (adam, adam) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment