Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn qmark-symbol?
- "Returns true, if sym is a symbol with name starting with a question mark."
- [sym]
- (and (symbol? sym)
- (= (first (name sym)) \?)))
- (defmacro with-fresh
- "Replace all symbols with a leading question mark with fresh lvars.
- In addition, all occurences of `_' are replaced with fresh lvars, one per
- occurence. That means, that in `forms' all occurences of ?foo will be
- unified, but all occurences of `_' are not."
- [& forms]
- (let [fs (clojure.walk/postwalk #(if (= '_ %) (gensym "?") %) forms)
- qsyms (vec (distinct (filter qmark-symbol? (flatten fs))))]
- `(fresh ~qsyms
- ~@fs)))
- ;; Using that, you can say something like
- (run* [q]
- (with-fresh
- (foo ?x ?p _)
- (bar _ ?x ?p)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement