Skip to content

Instantly share code, notes, and snippets.

@devijvers
Last active December 19, 2015 03:48
Show Gist options
  • Select an option

  • Save devijvers/5892294 to your computer and use it in GitHub Desktop.

Select an option

Save devijvers/5892294 to your computer and use it in GitHub Desktop.
(defn pluso [t1 t2 s]
(fn goal [a]
(let [args (map (partial walk a) [t1 t2 s])
fresh? (map lvar? args)
ground? (map not fresh?)]
(cond
(= [true true true] ground?) (if (= s (+ t1 t2)) a nil)
(= [true true false] ground?) (unify a s (+ t1 t2))
(= [true false true] ground?) (unify a t2 (- s t1))
(= [false true true] ground?) (unify a t1 (- s t2))
:else a))))
(run* [q]
(fresh [a]
(pluso q 4 a)
(== a 7)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment