Skip to content

Instantly share code, notes, and snippets.

@dsbw
Created September 5, 2016 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsbw/215a52c9b61d85bffa553a4fb009df30 to your computer and use it in GitHub Desktop.
Save dsbw/215a52c9b61d85bffa553a4fb009df30 to your computer and use it in GitHub Desktop.
(ns temp
(:refer-clojure :exclude [==])
(:use [clojure.core.logic])
(:use [clojure.core.logic.pldb]))
(db-rel parent x y)
(db-rel male x)
(db-rel female x)
(defn child [x y]
(parent y x))
(defn son [x y]
(all
(child x y)
(male x)))
(def g
(db
[parent 'Dad 'Junior]
[male 'Dad]
[male 'Junior]))
(with-db g (run* [q] (son 'Junior q)))
;;=> (Dad)
(defn son2 [x y]
(child x y)
(male x))
(with-db g (run* [q] (son2 'Junior q)))
;;=> (_0) ;;wut? We've got two variables, we've tested them both, where's the fresh coming from and why isn't it binding?
(defn son3 [x y]
(fresh [z]
(child x y)
(male x)))
(with-db g (run* [q] (son3 'Junior q)))
;;=> (Dad) ;;wut? Where did we bind z with anything? What has z to do with the answer? Why can't we take it out, like son2?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment