• (adorn-rules-set rs q)
Adorns the given rules-set for the given query. (rs) is a
rules-set, (q) is an adorned query.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/datalog/magic.clj:31 top

(defn adorn-rules-set
  "Adorns the given rules-set for the given query.  (rs) is a
   rules-set, (q) is an adorned query."
  [rs q]
  (let [i-preds (all-predicates rs)
        p-map (predicate-map rs)]
    (loop [nrs empty-rules-set ; The rules set being built
           needed #{(literal-predicate q)}]
      (if (empty? needed)
          nrs
          (let [pred (first needed)
                remaining (disj needed pred)
                base-pred (get-base-predicate pred)
                bindings (get-adorned-bindings pred)
                new-rules (p-map base-pred)
                new-adorned-rules (map (partial compute-sip bindings i-preds)
                                       new-rules)
                new-nrs (reduce conj nrs new-adorned-rules)
                current-preds (all-predicates new-nrs)
                not-needed? (fn [pred]
                              (or (current-preds pred)
                                  (-> pred get-base-predicate i-preds not)))
                add-pred (fn [np pred]
                           (if (not-needed? pred) np (conj np pred)))
                add-preds (fn [np rule]
                            (reduce add-pred np (map literal-predicate (:body rule))))
                new-needed (reduce add-preds remaining new-adorned-rules)]
            (recur new-nrs new-needed))))))
Vars in clojure.contrib.datalog.magic/adorn-rules-set: defn empty? let loop
Used in 0 other vars

Comments top

No comments for adorn-rules-set. Log in to add a comment.