remove-elements-not-satisfying-the-predicate

Liste des GroupesRevenir à cl lisp 
Sujet : remove-elements-not-satisfying-the-predicate
De : No_spamming (at) *nospam* noWhere_7073.org (B. Pym)
Groupes : comp.lang.lisp
Date : 03. Jul 2024, 02:42:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v626pj$1rui7$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Barry Margolin wrote:

In article ... (Christopher Dollin) writes:
So suppose someone says "please implement 'remove-if-not'. I would like
your solution to generate no garbage if possible and to be reasonably
efficient".
 
Here's a version I threw together quickly (note that it doesn't take
any options as the CL version does, and it only accepts a list, not
any sequence):
 
(defun simple-remove-if-not (test list)
  (let ((result nil))
    (dolist (item list)
      (unless (funcall test item)
        (push item result)))
    (nreverse result)))

What an egregiously bad name: "remove-if-not"
Scheme uses the sensible "filter".

* (remove-if-not 'oddp '(0 2 3 5))

(3 5)

* (simple-remove-if-not 'oddp '(0 2 3 5))

(0 2)

See?  The high and mighty CL (COBOL-like) guru got it wrong.
Of course, he probably didn't test it.  He has said that
he doesn't have CL (COBOL-like) installed on his computer.
It's not worth installing.

Date Sujet#  Auteur
3 Jul 24 * remove-elements-not-satisfying-the-predicate5B. Pym
3 Jul 24 `* Re: remove-elements-not-satisfying-the-predicate4Kaz Kylheku
3 Jul 24  `* Re: remove-elements-not-satisfying-the-predicate3Paul Rubin
3 Jul 24   `* Re: remove-elements-not-satisfying-the-predicate2Kaz Kylheku
3 Jul 24    `- Re: remove-elements-not-satisfying-the-predicate1Paul Rubin

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal