Great, thank you. I was thinking maybe there was some construct that could do this built-in, the way 'map' can double as 'zip'.
I looked through sugar and it looks very convenient; I'll be using it in future. Note that when I installed it, I got the following: [...snip lots of "raco setup: 0 skipping: <pkgs>/..." lines] raco setup: docs failure: query-exec: unable to open the database file error code: 14 SQL: "ATTACH $1 AS other" database: #<path:/Users/dstorrs/Library/Racket/6.3/doc/docindex.sqlite> mode: 'read-only file permissions: (write read) raco setup: --- installing collections --- raco setup: --- post-installing collections --- raco pkg install: packages installed, although setup reported errors Doesn't seem to have mattered and it might just be something weird about permissions on my system. I figured I'd mention it, though. Dave On Thu, Aug 4, 2016 at 5:04 PM, Matthew Butterick <m...@mbtype.com> wrote: > > On Aug 4, 2016, at 3:10 PM, David Storrs <david.sto...@gmail.com> wrote: > > I'd like to be able to iterate over a list N elements at a time -- e.g., > grab elements 1 and 2, do something with them, grab 3 and 4, etc. > > Your technique seems fine. You could use `split-at` if you wanted to save > a list operation, otherwise it's the standard recursion pattern: > > #lang racket > (define data '(("foo") ("bar") ("baz") ("jaz") ("quux") ("glug"))) > > (define (step-by-n func xs [num 2]) > (if (null? xs) > null > (let-values ([(head tail) (split-at xs num)]) > (cons (func head) (step-by-n func tail num))))) > > (step-by-n (λ (xx) (apply hash (map car xx))) data) > > (step-by-n (λ (xxx) (hash (caar xxx) (map car (cdr xxx)))) data 3) > > > I wrote a utility function called `slice-at` to handle this problem. [1] > > > [1] http://docs.racket-lang.org/sugar/#%28def._%28%28lib._ > sugar%2Flist..rkt%29._slice-at%29%29 -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.