anchor.diff:      (t (if (equal (car a) (car b))
              (symbol-list-compare (cdr a) (cdr b))
              (symbol-list-compare  (car a) (car b))))))
  +
  +
  +;;; FA
  +;;;  -(states, tokens, edges, start, accept),
  +;;;    - edges: (list state-0 token state-1)
  +
  +;;; Representation opptions
  +;;; - transition matrix
  +;;; - transition hash table
  +;;; - edge list
  +;;; - successor array
  +
  +(defstruct (fa (:constructor %make-fa))
  +  states
  +  tokens
  +  edges
  +  start
  +  accept
  +  reject)
  +
  +(defun fa-state-name (fa i)
  +  (aref (fa-states fa) i))
  +(defun fa-token-name (fa i)
  +  (aref (fa-tokens fa) i))
  +
  +(defun fa-map-edge-lists (result-type function fa)
  +  (map result-type function (fa-edges fa)))
  +
  +(defun fa-map-edges (result-type function fa)
  +  (fa-map-edge-lists result-type
  +                     (lambda (e) (funcall function (first e) (second e) (third e)))
  +                     fa))
  +
   
   (defun fa-subset-indices (subset sequence)
     "return a list of indices of sequence elements that intersect with subset"
  
positive.code:                       (push (list mark (fa-token-name nfa i-z) (gethash u d-hash))
                              d-edge)))))
        ;; result
        ;;(print nfa)
        ;;(print d-states)
        ;;(print (fa-subset-indices (fa-start nfa) d-states))
        ;;(print (fa-subset-indices (fa-accept nfa) d-states))
        (loop for ds across d-states
           do (assert (= 1 (loop for dt across d-states
                              counting (equal ds dt)))))
  
negative.code:            (new-token (i)
               (if token-map
                   (aref token-map i)
                   i))
             (state-translate (list)
               (mapcan (lambda (i) (when (new-state i)
                                (list (new-state i))))
                       list)))
      (let ((fa (%make-fa :states (cond ((null state-map) (fa-states fa))
                                        (t (map 'vector #'identity
                                                (loop
                                                   with i = -1
                                                   for x across (remove-duplicates state-map)
                                                   when x collect (incf i)))))
                          :tokens (if (null token-map)
                                      (fa-tokens fa)
                                      (let ((tokens (make-array (loop
                                                                   for x across
                                                                     (remove-duplicates token-map)
                                                                   count x)
                                                                :initial-element nil)))
                                        (loop with i = 0
                                           for x across token-map
                                           when x
                                           do (setf (aref tokens (aref token-map i))
                                                    (aref (fa-tokens fa) i)))
                                        tokens))
                          :start (state-translate (fa-start fa))
                          :accept (state-translate (fa-accept fa))
                          :edges (let ((hash (make-hash-table :test #'equal)))
                                   (fa-map-edges nil
                                                 (lambda (q0 z q1)
                                                   (when (and (new-state q0)
                                                              (new-token z)
                                                              (new-state q1))
                                                     (setf (gethash (list (new-state q0)
                                                                          (new-token z)
                                                                          (new-state q1))
                                                                    hash)
                                                           t)))
                                                 fa)
                                   (loop for key being the hash-keys of hash
                                      collect key)))))
        (when sort
          (setf (fa-edges fa) (sort (fa-edges fa) #'symbol-list-compare)
                (fa-start fa) (sort (fa-start fa) #'<)
                (fa-accept fa) (sort (fa-start fa) #'<)))
        fa)))
  
  
  ;;; Regex
  