Skip to content

Instantly share code, notes, and snippets.

@bdaniels
bdaniels / sqrt.clj
Created November 14, 2018 04:25
Square Root — Fake Relational Version?
;; Trying to learn the practice of making methods into relations
;; by making sure it can be used forward and backwards. This method
;; of looking at which variable is bound seems to work under the method
;; ordering shown below. However, this doesn't seem to me that it is
;; truely relational.
;;
;; Thoughts?
(defn sqrto [x y]
"A relationship such that y is the square root of y.
@bdaniels
bdaniels / gist:3287562
Created August 7, 2012 17:29
I thought that the first constraint on design would cause all to fail if null, but I'm getting results from the conde statement afterwards in my unit tests.
; Logic Code
(defn uri-path [design view search path]
(logic/!= nil design)
(logic/conde
[(logic/!= nil view) (logic/== ["_design" design "_view" view] path)]))
; Unit test
(test/deftest test-path
(test/is (= '()
(logic/run* [q] (db/uri-path nil "view" "search" q))))
@bdaniels
bdaniels / Reasonable Clojure Diff
Created July 18, 2012 17:05
Two examples from Reasonable Schemer that I translated to Clojure and am seeing different results.
;; This is #58 from page 14.
(run* [r]
(fresh [x y z]
(conde
[(== y x)(fresh [x] (== z x))]
[(fresh [x] (== y x) (== z x))]
[fail])
(== (cons y (cons z ())) r)))
; expected: ((_.0 _.1) (_.0 _.1))
; actual: ((_.0 _.1) (_.0 _.0))