Skip to content

Instantly share code, notes, and snippets.

Created October 16, 2016 03:59
What would you like to do?
List size goal operator with core.logic
;; These two goals taken from
(defn sumo [l sum]
(fresh [head tail tail-sum]
[(== l ()) (== sum 0)]
[(conso head tail l)
(fd/+ head tail-sum sum)
(sumo tail tail-sum)])))
(defn everyo [l f]
(fresh [head tail]
[(== l ())]
[(conso head tail l)
(f head)
(everyo tail f)])))
(defn sizeo [l size]
(fresh [tail tail-size]
[(== l ()) (== size 0)]
[(resto l tail)
(fd/+ size -1 tail-size)
(sizeo tail tail-size)])))
(run 1 [l]
(fresh [size]
(fd/in size (fd/interval 0 2))
(everyo l #(fd/in % (fd/interval 1 10)))
(sumo l 10)
(sizeo l size)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment