fork download
  1. ; http://stackoverflow.com/q/36683515/1116364
  2.  
  3. (define (take lst n)
  4. (if (= n 0)
  5. '()
  6. (cons (car lst) (take (cdr lst) (- n 1)))))
  7.  
  8. (define (partition-all n step coll)
  9. (if (not (null? coll))
  10. (cons (take coll (min n (length coll)))
  11. (partition-all n step (list-tail coll (min (length coll) step))))
  12. '()))
  13.  
  14.  
  15. (display (partition-all 3 2 '(a b c d e f g)))
  16.  
Success #stdin #stdout 0.03s 8616KB
stdin
Standard input is empty
stdout
((a b c) (c d e) (e f g) (g))