 (macroexpand
   '(def-tuple-rule my-tuple-rule
      "Docstring!!"
-     [[?e :todo/title _] (> ?e 1)]
+     [[?e :todo/title _]]
      [:exists [:todo/done]]
      =>
      (println "Hello!")))

;       (not (empty? env)) (assoc :env matching-env)))))
(defn is-binding? [x]
  ;(println "Is a binding?" x)
  (= (first (name x)) \?))

(defn rewrite-lhs [forms]
  (println "Forms" forms)
  (map (fn main-one [form]
         ;(println "Form" form)
         ;(println "Type" (type form))
         ;(println "is op" (dsl/ops (first form)))
         (if (dsl/ops (first form))
           form
           (let [bindings (filter
                            (juxt (comp identity second)
                                  (comp is-binding? second))
                            {:e (first form)
                             :a (second form)
                             :v (last form)})
                 attribute (or (keyword? (:a bindings)) :all)]
             (prn "Bindigs are" bindings)
             ;(println "attribute is" attribute)
            (vector
              attribute
              (map (fn last-one [[k v]]
                       (println "k v bindings" k v)
                       (list '= v (symbol (name k)))) bindings)))))

             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)))))))

