   [actual expected & kind]
   (let [starting-candidate  {:actual-found [], :expected-found [],
 			     :expected-skipped-over [], :expected expected }
-	starting-expected-variants (all-expected-variants expected)
+	starting-expected-permutations (all-expected-permutations expected)
 	gaps-ok? (some #{:gaps-ok} kind)]
-    (println :in-any-order gaps-ok?)
     (loop [walking-actual   actual
-	   walking-expected (first starting-expected-variants)
-	   expected-variants starting-expected-variants
+	   walking-expected (first starting-expected-permutations)
+	   expected-permutations starting-expected-permutations
 	   best-so-far      starting-candidate
 	   candidate        starting-candidate]
 

	    ;; window good so far, keep working on it
	    (recur (rest walking-actual)
		   (concat (:expected-skipped-over candidate) (rest walking-expected))
		   expected-variants
		   best-so-far
		   (tack-on-to candidate
			       :actual-found (first walking-actual)
			       :expected-found (first walking-expected)))

	    (not (empty? (rest walking-expected)))
	    ;; Perhaps another value in the current expected variant will work.
	    (recur walking-actual
		   (rest walking-expected)
		   expected-variants
		   best-so-far
		   (tack-on-to candidate
			       :expected-skipped-over (first walking-expected)))

	    (not (empty? (rest walking-actual)))
	    (if gaps-ok?
	      ;; Current actual doesn't match anything expected. Lose it and
	      ;; try other actuals on same expected variant.
	      (recur (rest walking-actual)
		     (first expected-variants)
		     expected-variants
		     (better-of candidate best-so-far)
		     candidate)

	      ;; Current window didn't work. Slide it down, reusing same expected variant
	      (recur (rest (concat (:actual-found candidate) walking-actual))
		   (first expected-variants)
		   expected-variants
		   (better-of candidate best-so-far)
                   starting-candidate))
	    
	    (not (empty? (rest expected-variants)))
	    ;; Can't slide window any further, so let's try another variant
            (recur actual
                   (second expected-variants)
		   (rest expected-variants)
		   (better-of candidate best-so-far)
                   starting-candidate)

	    :else ; no variant left, window used up. give up.
	    (better-of candidate best-so-far)))))

;; (defmethod seq-comparison #{:in-any-order}
;;   [actual expected & kind]
;;   (let [starting-candidate  {:actual-found [], :expected-found [],
;; 			     :expected-skipped-over [], :expected expected }
;; 	starting-expected-variants (all-expected-variants expected)]
;;     (loop [walking-actual   actual
;;            walking-expected (first starting-expected-variants)
;; 	   expected-variants starting-expected-variants
;;            best-so-far      starting-candidate
;;            candidate        starting-candidate]

;;       (cond (or (empty? walking-actual) (empty? walking-expected))
;;             (better-of candidate best-so-far)

;; 	    (extended-= (first walking-actual) (first walking-expected))
;; 	    ;; window good so far, keep working on it
;; 	    (recur (rest walking-actual)
;; 		   (concat (:expected-skipped-over candidate) (rest walking-expected))
;; 		   expected-variants
;; 		   best-so-far
;; 		   (tack-on-to candidate
;; 			       :actual-found (first walking-actual)
;; 			       :expected-found (first walking-expected)))

;; 	    (not (empty? (rest walking-expected)))
;; 	    ;; Perhaps another value in the current expected variant will work.
;; 	    (recur walking-actual
;; 		   (rest walking-expected)
;; 		   expected-variants
;; 		   best-so-far
;; 		   (tack-on-to candidate
;; 			       :expected-skipped-over (first walking-expected)))

;; 	    (not (empty? (rest walking-actual)))
;; 	    ;; Current window didn't work. Slide it down, reusing same expected variant
;;             (recur (rest (concat (:actual-found candidate) walking-actual))
;; 		   (first expected-variants)
;; 		   expected-variants
;; 		   (better-of candidate best-so-far)
;;                    starting-candidate)
	    
;; 	    (not (empty? (rest expected-variants)))
;; 	    ;; Can't slide window any further, so let's try another variant
;;             (recur actual
;;                    (second expected-variants)
;; 		   (rest expected-variants)
;; 		   (better-of candidate best-so-far)
;;                    starting-candidate)

;; 	    :else ; no variant left, window used up. give up.
;; 	    (better-of candidate best-so-far)))))


;; (defmethod seq-comparison #{:in-any-order :gaps-ok}
;;   [actual expected & kind]
;;   (let [starting-candidate  {:actual-found [], :expected-found [],
;; 			     :expected-skipped-over [], :expected expected }
;; 	starting-expected-variants (all-expected-variants expected)]
;;     ;; (println "=============")
;;     ;; (println actual expected)
;;     ;; (println starting-expected-variants)
    
;;     (loop [walking-actual   actual
;;            walking-expected (first starting-expected-variants)
;; 	   expected-variants starting-expected-variants
;;            best-so-far      starting-candidate
;;            candidate        starting-candidate]
;;       ;; (println "walking " walking-actual "of" walking-expected)
;;       ;; (println "remainder " expected-variants)

;;       (cond (or (empty? walking-actual) (empty? walking-expected))
;;             (better-of candidate best-so-far)

;; 	    (extended-= (first walking-actual) (first walking-expected))
;; 	    ;; actual good so far, keep working on it
;; 	    (recur (rest walking-actual)
;; 		   (concat (:expected-skipped-over candidate) (rest walking-expected))
;; 		   expected-variants
;; 		   best-so-far
;; 		   (tack-on-to candidate
;; 			       :actual-found (first walking-actual)
;; 			       :expected-found (first walking-expected)))

;; 	    (not (empty? (rest walking-expected)))
;; 	    ;; Perhaps another value in the current expected variant will work.
;; 	    (recur walking-actual
;; 		   (rest walking-expected)
;; 		   expected-variants
;; 		   best-so-far
;; 		   (tack-on-to candidate
;; 			       :expected-skipped-over (first walking-expected)))

;; 	    (not (empty? (rest walking-actual)))
;; 	    ;; Current actual doesn't match anything expected. Lose it and
;; 	    ;; try other actuals on same expected variant.
;;             (recur (rest walking-actual)
;; 		   (first expected-variants)
;; 		   expected-variants
;; 		   (better-of candidate best-so-far)
;;                    candidate)
	    
;; 	    (not (empty? (rest expected-variants)))
;; 	    ;; Can't slide window any further, so let's try another variant
;;             (recur actual
;;                    (second expected-variants)
;; 		   (rest expected-variants)
;; 		   (better-of candidate best-so-far)
;;                    starting-candidate)

;; 	    :else ; no variant left, window used up. give up.
;; 	    (better-of candidate best-so-far)))))

(defmethod seq-comparison :strict-order
  [actual expected & kind]

	argmap `(hash-map ~@first-kvs)]
    `(merge-with conj ~hashmap ~argmap)))

(defn- all-expected-permutations [expected]
  (cond (not-any? extended-fn? expected)
	[expected]

