anchor.diff:  ;;;          (sees ...)
   ;;;           anything that depends on only these or lower
   ;;;
  +;;; Within each layer the ordering is arbitrary, EXCEPT that if a rule X that
  +;;; relies on the negation of a rule Y, then Y must come before X.
   
   
  -;;;; Ordering -----------------------------------------------------------------
  +;;;; Utils --------------------------------------------------------------------
   (defun-match bare-term (term)
     (`(not ,x) x)
     (x x))
  
positive.code: (in-readtable :fare-quasiquote)
  
  
  ;;;; Overview
  ;;; We start with a set of grounded rules like: ((next bar) x y (true foo)).
  ;;;
  ;;; We need to turn map each term to a unique integer, making sure that they end
  
negative.code:                      (digraph:insert-edge graph head dependency))))))
      graph))
  
  
  (defun order-rules (rules)
    (-> rules
      build-layer-graph
      digraph:topological-sort))
  
  
  ;;;; Scratch ------------------------------------------------------------------
  ; (defparameter *g*
  ;   (build-layer-graph (list
  ;                        '((t foo) a)
  ;                        '((t bar) a (not (t foo)))
  ;                        '((t baz) a (not (t bar)))
  ;                        '((t dogs) a x)
  ;                        '((t cats) a (not (t dogs)))
  ;                        )))
  
  ; (order-rules (list
  ;                '((t foo) a)
  ;                '((t bar) a (not (t foo)))
  ;                '((t baz) a (not (t bar)))))
  
  (-<> '(
         ((foo x) (true 1))
         (cats (foo x))
         (dogs (not cats))
         ((bar x) (true 2) (does q))
         (mice (bar x))
         ((legal x) (true 3))
         )
    partition-predicates
    ; print-hash-table
    )
  
  (print-hash-table *)
  