Skip to content

Instantly share code, notes, and snippets.

@swannodette
Last active January 9, 2024 11:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save swannodette/8876121 to your computer and use it in GitHub Desktop.
Save swannodette/8876121 to your computer and use it in GitHub Desktop.
(declare numbero*)
(defn symbolo* [x]
(reify
IConstraintStep
(-step [this s]
(reify
clojure.lang.IFn
(invoke [_ s]
(let [x (walk s x)]
(when (symbol? x)
((remcg this) s))))
IRunnable
(-runnable? [_]
(not (lvar? (walk s x))))))
IVerifyConstraint
(-verify [_ a cs]
(not (some (fn [c] (= (-rator c) `numbero))
(map (:cm cs) (get (:km cs) (root-var a x))))))
IConstraintOp
(-rator [_] `symbolo)
(-rands [_] [x])
IReifiableConstraint
(-reifyc [c v r s]
(when-not (lvar? (walk r x))
`(symbolo ~(-reify s x r))))
IConstraintWatchedStores
(-watched-stores [this] #{:clojure.core.logic/subst})))
(defn symbolo [x]
(cgoal (symbolo* x)))
(defn numbero* [x]
(reify
IConstraintStep
(-step [this s]
(reify
clojure.lang.IFn
(invoke [_ s]
(let [x (walk s x)]
(when (number? x)
((remcg this) s))))
IRunnable
(-runnable? [_]
(not (lvar? (walk s x))))))
IVerifyConstraint
(-verify [_ a cs]
(not (some (fn [c] (= (-rator c) `symbolo))
(map (:cm cs) (get (:km cs) (root-var a x))))))
IConstraintOp
(-rator [_] `numbero)
(-rands [_] [x])
IReifiableConstraint
(-reifyc [c v r s]
(when-not (lvar? (walk r x))
`(numbero ~(-reify s x r))))
IConstraintWatchedStores
(-watched-stores [this] #{:clojure.core.logic/subst})))
(defn numbero [x]
(cgoal (numbero* x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment