0.8.4-SNAPSHOT Arrow_down_16x16
  • (tabled args & grest)
Macro for defining a tabled goal. Prefer ^:tabled with the
defne/a/u forms over using this directly.

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/core/logic.clj:2109 top

(defmacro tabled
  "Macro for defining a tabled goal. Prefer ^:tabled with the 
  defne/a/u forms over using this directly."
  [args & grest]
  (let [uuid (symbol (str "tabled-" (UUID/randomUUID)))]
    `(fn ~uuid [~@args]
       (let [argv# ~args]
         (fn [a#]
           (let [key#    (-reify a# argv#)
                 tables# (:ts a#)
                 tables# (if-not (contains? @tables# ~uuid)
                           (swap! tables#
                             (fn [tables#]
                               (if (contains? tables# ~uuid)
                                 tables#
                                 (assoc tables# ~uuid (atom {})))))
                           @tables#)
                 table#  (get tables# ~uuid)]
             (if-not (contains? @table# key#)
               (let [table# (swap! table#
                              (fn [table#]
                                (if (contains? table# key#)
                                  table#
                                  (assoc table# key# (atom (answer-cache))))))
                     cache# (get table# key#)]
                 ((fresh []
                    ~@grest
                    (master argv# cache#)) a#))
               (let [cache# (get @table# key#)]
                 (reuse a# argv# cache# nil nil)))))))))
Vars in clojure.core.logic/tabled:
Used in 0 other vars

Comments top

No comments for tabled. Log in to add a comment.