Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will be awarded the Nobel Peace Prize... posthumously.


comp / comp.lang.lisp / Re: removeText

SubjectAuthor
o Re: removeTextB. Pym

1
Subject: Re: removeText
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Thu, 26 Sep 2024 02:07 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: removeText
Date: Thu, 26 Sep 2024 02:07:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <vd2fk7$18bg$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 26 Sep 2024 04:07:04 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2b7f8b0e9338bb313cc30be8fc596d5b";
logging-data="41328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195kQ/Uz6ZP/Q/vNf2/R14f"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:ewTEDZKCD/ZS6isKQAhT/rYdLfo=
View all headers

A monkey (<p....@javamonkey.com>) wrote:

> Kenny Tilton <ktilton@nyc.rr.com> writes:
>
> > Cool. Now here is a version using loop:
> >
> > (defun remove-text (text-to-remove text)
> > (loop with remove-length = (length text-to-remove)
> > for i = (search text-to-remove text)
> > then (search text-to-remove text :start2 i)
> > while i
> > do (setq text (concatenate 'string
> > (subseq text 0 i)
> > (subseq text (+ i remove-length))))
> > finally (return text)))
>
> Just to point out a useful LOOP idiom, here's another way:
>
> (defun remove-text (text-to-remove text)
> (with-output-to-string (s)
> (loop
> with remove-length = (length text-to-remove)
> for prev-end = 0 then (+ start remove-length)
> for start = (search text-to-remove text :start2 prev-end)
> do (write-string text s :start prev-end :end start)
> while start)))

Gauche Scheme:

(define (remove-text trash text)
(string-join (string-split text trash) ""))

1

rocksolid light 0.9.8
clearnet tor