Re: remove-elements-not-satisfying-the-predicate

Liste des GroupesRevenir à cl lisp 
Sujet : Re: remove-elements-not-satisfying-the-predicate
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.lisp
Date : 03. Jul 2024, 03:02:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240702175036.784@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-07-03, B. Pym <No_spamming@noWhere_7073.org> wrote:
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".

Although it is a verbose name, which contains a double negative
(removing is negative, as is "not") Scheme's name is completely idiotic.

Filtering is an activity in which we separate a mixture into
material that is wanted and that is unwanted.

The name filter doesn't tell me what is returned: the wanted
material or the unwanted material?

Sometimes what you want is captured in a filter (e.g. cleaned
vegetables in a strainer).  Sometimes the unwanted material is captured
in a filter; what passes through is what you want: e.g. cleaner air.

So even if we specify that the result of filtering something is that
which is trapped in the filter, that doesn't inform us whether that
material is what we want to keep.

If "filter" has to be in the name, you want names like filter-for and
filter-out. Filter for this condition (what we want to keep).  Filter
out on this condition (what we want to reject). GNU make has
$(filter-out ...). Unfortunately, it pairs that with $(filter ...).

A much better name is keep-if, which is what I used in TXR Lisp.
It complements remove-if.   A user contributed a function called
separate which returns the keep-if and remove-if results together.

separate is a synonym for filter; it would be justifiable for separate
to be called filter.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

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