From: Ken A. <kan...@bb...> - 2002-11-07 23:27:51
|
Yes, In elf/sort.scm there is (by n xs): (define (by n xs) (define (by0 i xs items so-far) (if (= i 0) (by0 n xs '() (cons (reverse items) so-far)) (if (null? xs) (finish items so-far) (by0 (- i 1) (cdr xs) (cons (car xs) items) so-far)))) (define (finish items so-far) (reverse (if (null? items) so-far (cons (reverse items) so-far)))) (assert (> n 0)) (by0 n xs '() '())) I think i got this idea from Peter Norvig: Put parens around your data any way it comes and use (by) and (map) to organize it into the way you want it. k At 05:36 PM 11/7/2002, Renu Kurien Bostwick wrote: >Ken - > >Do you know of an easy way (jscheme function perhaps) that'll break up >a list into sublists that are max of n long? > >'(a b c d e f g h i j) with n=3 would become > >'((a b c) (d e f) (g h i) (j)) > >or > >'((a) (b c d) (e f g) (h i j)) > >The ordering isn't important to me. I've been writing my own function >to do the split but it involves converting to vectors and back to >lists. Is there a more elegant solution? > >Thanks, >Renu > >-- >----------------------- >Renu Kurien Bostwick >re...@bb... >(617) 873-4543 >----------------------- |