   =>
   (println "Retracting entity " ?entity)
   (doseq [tuple ?entity] (retract! tuple)))
+; DSL notes on how we might handle retractions such as these.
+; Follows convention for namespaced keyword destructuring slated for CLJ 1.9
+; (retract {:todo/keys :all})
+; (retract {:todo/keys [title visible done]})
+; (retract-entity ?e)
 
-;(defrule no-done-todos-when-clear-completed-action
-;  ; when clear completed action exists
-;  [:exists [:ui/clear-completed]]
-;  ; and there's a todo that is marked "done"
-;  [:todo/title [[e a v]] (= ?e e)]
-;  [:todo/done [[e a v]] (= ?e e)]
-;  [?entity <- (acc/all) :from [:all [[e a v]] (= ?e e)]]
-;  =>
-;  ; DSL notes on how we might handle retractions such as these.
-;  ; Follows convention for namespaced keyword destructuring slated for CLJ 1.9
-;  ; (retract {:todo/keys :all})
-;  ; (retract {:todo/keys [title visible done]})
-;  ; (retract-entity ?e)
-;  ;; can we run a query in RHS???
-;  (println "Retracting entity " ?entity)
-;  (doseq [tuple ?entity] (retract! tuple)))
-
-;TODO. This doesn't work and we would like the first condition to be expressed with
-; square brackets optional.
-; Also need to handle cases of nested ops as in condition 2. Should do this on
-; same pass as adding support for matching in the rightmost part of the condition
 (def-tuple-rule clear-completed-action-is-done-when-no-done-todos
   [?action <- [:ui/clear-completed]]
   [:not [:exists [:todo/done]]]
   =>
   (println "Clear-completed action finished. Retracting " ?action)
   (retract! ?action))
-
-;(defrule clear-completed-action-is-done-when-no-done-todos
-;  [?action <- :ui/clear-completed]
-;  [:not [:exists [:todo/done]]]
-;  =>
-;  (println "Clear-completed action finished. Retracting " ?action)
-;  (retract! ?action))
-
-;(defrule todo-is-visible-when-a-friday
-;  [:exists [:today/is-friday]]
-;  [:todo/title [[e a v]] (= ?e e)]
-;  =>
-;  (println "BOOM")
-;  (insert! [?e :todo/visible* :tag]))
-;
-;(defrule todo-visible-*
-;  [:exists [:todo/visible* [[e a v]] (= e? e)]]
-;  =>
-;  (insert! [?e :todo/visible :tag]))
 
 ;(defrule print-all-facts
 ;  [?fact <- :all [[e a v]] (= ?e e) (= ?a a) (= ?v v)]

  =>
  (insert! [?e :todo/visible :tag]))

;(defrule todo-is-visible-when-filter-active-and-todo-not-done
;  [:ui/visibility-filter [[e a v]] (= v :active)]
;  [:todo/title [[e a v]] (= ?e e)]
;  [:not [:todo/done [[e a v]] (= e ?e)]]
;  =>
;  (insert! [?e :todo/visible :tag]))

(def-tuple-rule toggle-all-complete
  ; when toggle complete action exists
  [:exists [:ui/toggle-complete]]
  ; and there's a todo that isn't marked "done"
  [[?e :todo/title]]
  [:not [?e :todo/done]]
  =>
  (println "Marked done via toggle complete:" ?e)
  (insert-unconditional! [?e :todo/done :done]))

;(defrule toggle-all-complete
;  ; when toggle complete action exists
;  [:exists [:ui/toggle-complete]]
;  ; and there's a todo that isn't marked "done"
;  [:todo/title [[e a v]] (= ?e e)]
;  [:not [:todo/done [[e a v]] (= ?e e)]]
;  =>
;  (println "Marked done via toggle complete:" ?e)
;  (insert-unconditional! [?e :todo/done :done]))

;TODO. check if :test is considered an op. Note that
; clara's syntax allows ?binding <- :attribute with no brackets
; so we need to support that as well
; Accum *shouldn't* be a problem.
; Debugging should be easier in CLJ at this point, should just need to compare expansions
(def-tuple-rule remove-toggle-complete-when-all-todos-done
  [?toggle <- :ui/toggle-complete]
  [?total <- (acc/count) :from [:todo/title]]

                                  clara-tups->maps]]
            [clara.rules.accumulators :as acc]
            [todomvc.tuplerules :refer-macros [def-tuple-session def-tuple-rule]]))

(defn todo-tx [id title done]
  (merge
