 (ns todomvc.tuple-rule
-    (:require [clara.rules.compiler :as com]
+    (:require [clara.rules :refer [defrule]]
+              [clara.rules.compiler :as com]
               [clara.rules.dsl :as dsl]))
 
 

             body       (if doc (rest body) body)
             properties (if (map? (first body)) (first body) nil)
             definition (if properties (rest body) body)
             {:keys [lhs rhs]} (dsl/split-lhs-rhs definition)
             lhs-new    (rewrite-lhs (first lhs))]
         (println "LHS" lhs-new)
         (println "RHS" rhs)
         (when-not rhs
           (throw (ex-info (str "Invalid rule " name ". No RHS (missing =>?).")
                    {})))
         `(def ~(vary-meta name assoc :rule true :doc doc)
            (cond-> ~(dsl/parse-rule* lhs-new rhs properties {} (meta &form))
              ~name (assoc :name ~(str (clojure.core/name (ns-name *ns*)) "/" (clojure.core/name name)))
              ~doc (assoc :doc ~doc)))))))

;LHS ([[?e :todo/title _]] [:exists [:todo/done]])

;LHS ([:todo/title [[e a v]] (= ?e e)] [:exists [:todo/done]])
(rewrite-lhs (first
               '([
                  [?e :todo/title _]
                  [:exists [:todo/done]]])))

(macroexpand
  '(def-tuple-rule my-tuple-rule

     (println "Hello!")))

(macroexpand
  '(defrule my-regular-rule
     "Docstring!!"
     [:todo/title [[e a v]] (= ?e e)]
     [:exists [:todo/done]]
