Deutsch English Français Italiano |
<20240702175036.784@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.lisp Subject: Re: remove-elements-not-satisfying-the-predicate Date: Wed, 3 Jul 2024 01:02:16 -0000 (UTC) Organization: A noiseless patient Spider Lines: 55 Message-ID: <20240702175036.784@kylheku.com> References: <v626pj$1rui7$1@dont-email.me> Injection-Date: Wed, 03 Jul 2024 03:02:17 +0200 (CEST) Injection-Info: dont-email.me; posting-host="30e244ac737476d78edd2cd6194d0a15"; logging-data="1967023"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IRIxFQ70g1dLj0IJrnQz1xAJLRkDtV7w=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:KYczZi9OXnjEnfXkks/TFHSPzqM= Bytes: 3071 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