Re: Idiom for gathering pairs from a list?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Idiom for gathering pairs from a list?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 26. Aug 2024, 09:02:56
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vah9at$2c33s$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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 ...)

Gauche Scheme

(use util.match)

(match-let loop (((k v . more) '(a 2  b 3  c 4)))
  (print (list k v))
  (when (pair? more) (loop more)))

(a 2)
(b 3)
(c 4)

Date Sujet#  Auteur
26 Aug 24 o Re: Idiom for gathering pairs from a list?1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal