Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You are as I am with You.


comp / comp.lang.scheme / Re: A Long Piece Of Lisp Code

SubjectAuthor
o Re: A Long Piece Of Lisp CodeB. Pym

1
Subject: Re: A Long Piece Of Lisp Code
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Tue, 17 Sep 2024 11:11 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
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=
View all headers

> (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)

1

rocksolid light 0.9.8
clearnet tor