| Deutsch English Français Italiano |
|
<vcbo5m$3g34k$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.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" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: A Long Piece Of Lisp Code
Date: Tue, 17 Sep 2024 11:11:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <vcbo5m$3g34k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 17 Sep 2024 13:11:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a46abdd1c4c6debf9f002d978f341ceb";
logging-data="3673236"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191feE+dPzyXRYoCFSKeggl"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:JyxLOblgrfzhYTBuThv8kk7ixEE=
Bytes: 1449
> (defun split-if (fn lst)
> (let ((acc nil))
> (do ((src lst (cdr src)))
> ((or (null src) (funcall fn (car src)))
> (values (nreverse acc) src))
> (push (car src) acc))))
Scheme
(define (split-if fn lst)
(do ((src lst (cdr src))
(acc '() (cons (car src) acc)))
((or (null? src) (fn (car src)))
(values (reverse acc) src))))
(split-if odd? '(0 2 4 5 7))
===>
(0 2 4)
(5 7)
(split-if odd? '(0 2 4 52 70))
===>
(0 2 4 52 70)
()
(split-if odd? '(3 0 2 4 52 70))
===>
()
(3 0 2 4 52 70)