Created
August 3, 2012 01:53
-
-
Save gfredericks/3243373 to your computer and use it in GitHub Desktop.
integero
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
(defn integero** | |
[n x] | |
(conde ((== n x)) | |
((== (- n) x)) | |
((integero** (inc n) x)))) | |
(defmacro integero* | |
[x] | |
`(fn [a#] | |
(let [w# (walk a# ~x)] | |
(if-not (lvar? w#) | |
(if (integer? w#) | |
a# | |
nil) | |
(-inc | |
(mplus* | |
(bind* a# (== 0 ~x)) | |
(bind* a# (integero** 1 ~x)))))))) | |
(defn integero | |
[x] | |
(integero* x)) | |
(do | |
(assert (empty? (run 4 [q] (integero 8.4)))) | |
(assert (= ['_.0]) (run 4 [q] (integero 8))) | |
(assert (= 4 (count (run 4 [q] (integero q)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment