public
Created

Usage of clojure.core.logic

  • Download Gist
logical.core.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
(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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.