Deutsch English Français Italiano |
<v626pj$1rui7$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" <No_spamming@noWhere_7073.org> Newsgroups: comp.lang.lisp Subject: remove-elements-not-satisfying-the-predicate Date: Wed, 3 Jul 2024 00:42:32 -0000 (UTC) Organization: A noiseless patient Spider Lines: 33 Message-ID: <v626pj$1rui7$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Wed, 03 Jul 2024 02:42:32 +0200 (CEST) Injection-Info: dont-email.me; posting-host="1439b84b29baa786e04afeccb1cf6774"; logging-data="1964615"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SVx8Uf1H3ptwswR4JP5h0" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:x5OxM6Hb5eMRw9kKyH7EITaTIPE= Bytes: 1866 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.