Re: novice: mapcan use?

Liste des GroupesRevenir à cl scheme 
Sujet : Re: novice: mapcan use?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 11. Sep 2024, 03:44:56
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbqsmn$3cn2o$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Pascal Costanza wrote:

I have used NRECONC.  When you are processing a list and the
interesting stuff is at the head of the list, you write a loop like
this:
>
  (do ((tail      list (cdr tail))
       (processed '()  (cons (do-something (car tail))
                             processed)))
      ((done? ...) (nreconc processed tail)))
>
The nreconc reverses the processed stuff (which is accumulated
backwards) and pastes it on to the remaining element of LIST.
 
Ah, finally a clue. Thanks for that!
 
Indeed, I could have used something like that before, but came up with a
solution with LOOP that looks like this:
 
(loop for (car . cdr) on list
       collect (do-something car) into processed
       until done
       finally (return (nconc processed cdr)))

Gauche Scheme

(use srfi-1)  ;; span

(receive (nums rest) (span number? '(2 3 4 a b c))
  (append (map square nums) rest))
  ===>
(4 9 16 a b c)


(lope dolist-by x xs cdr '(2 3 4 a b c)
  until (not (number? x))
  collect-in (sqr x) processed
  returning (append processed xs))

===>
'(4 9 16 a b c)

Date Sujet#  Auteur
11 Sep 24 o Re: novice: mapcan use?1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal