On Wed, Aug 10, 2016 at 5:50 AM, Greg Hendershott <greghendersh...@gmail.com
> wrote:

> > I feel like there should be a simpler way to do this, but I haven't found
> > one despite much Googling and reading of docs about "for" and its
> siblings.
> > Can someone point me the right way?
> >
> > 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.
> >
> > This will do the job, but I suspect there's a more built-in way:
> >
> > (define data '(("foo") ("bar")  ("baz")  ("jaz") ("quux") ("glug")))
>
> racket/sequence provides an `in-slice` sequence to use with `for` forms:
>
> https://docs.racket-lang.org/reference/sequences.html#%
> 28def._%28%28lib._racket%2Fsequence..rkt%29._in-slice%29%29
>

in-slice produces lists of N elements, so I guess if I wanted to iterate
over every 2nd element I would use something like this?:

(define data '(("foo") ("bar")  ("baz")  ("jaz") ("quux") ("glug")))
(for ((x (~>  data
    in-list
    (in-slice _ 2)
    (map car))))
...do something...)

-- 
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