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.

Reply via email to