Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Idiom for gathering pairs from a list?

9 views
Skip to first unread message

Robert L.

unread,
May 21, 2018, 11:06:43 PM5/21/18
to
Zach Beane wrote:

> "bradb" <brad.beveri...@gmail.com> writes:
> > I'm using CL-PPCRE, and some functions return lists of start and end
> > matches, so a return might be
> > (0 2 4 7 10 15), three matches.
> > Right now I loop over the matches like
> > (loop :for match :on (all-matches scanner text :start start) :by
> > #'cddr
> > :do (let ((start (first match))
> > (end (second match)))
> > (subseq text start end))
>
> > Is there a nicer way to gather the pairs than that?
>
> LOOP destructures. Try this:
>
> (loop for (start end) on (all-matches ...) by #'cddr do ...)

(define text "abcdefghijklmnopq")

(g.each
(compose displayln (curry apply substring text))
(gen-slices 2 '(0 2 4 7 10 15)))

===>
ab
efg
klmno

--
"They created ... an America which is not the real America ... but ultimately
this shadow America becomes ... so widely disseminated that its images and its
values come to devour the real America. And so the grand irony of all of
Hollywood is that Americans come to define themselves by the shadow of
America...." http://archive.org/details/nolies
0 new messages