(define (windows ls n) (let loop ((ls ls) (res '())) (if (null? (drop ls n)) (cons (take-right ls n) res) (loop (drop-right ls 1) (cons (take-right ls n) res))))) ;; (windows '(0 1 2 3 4 5 6 7 8 9) 4) ;; => ((0 1 2 3) (1 2 3 4) (2 3 4 5) (3 4 5 6) (4 5 6 7) (5 6 7 8) (6 7 8 9)) ;; (windows '(0 1 2 3 4 5 6 7 8 9) 3) ;; => ((0 1 2) (1 2 3) (2 3 4) (3 4 5) (4 5 6) (5 6 7) (6 7 8) (7 8 9))