Find stride across lists


I store a matrix as a list of rows, where each row is a list of column values for that row. I want to check if there is a column in the matrix that satisfies a comparator p.

p can actually return any non-#f value and that value is returned as-is. And the lists don't actually have to represent a matrix: the rows don't all need to have the same number of columns.


(define (find-stride p . a*)
       (lambda (a)
         (map car a)))
       (lambda (a)
         (map cdr a)))
       (lambda (a)
         (memq '() a)))
       (lambda (a*)
         (and (not (any-null a*))
              (or (apply p (car-of a*))
                  (find* (cdr-of a*)))))))
    (find* a*)))

Credit: Nils M. Holm (ref: exists.scm)


(find-stride < '(9 1) '(8 2) '(7 3))
;; ==> #t  ; because (< 1 2 3)

Back to the Scheme Cookbook