Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #26: first Saturday after first full moon in Winter


comp / comp.lang.scheme / Re: separating words

SubjectAuthor
o Re: separating wordsB. Pym

1
Subject: Re: separating words
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sat, 7 Sep 2024 05:25 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: separating words
Date: Sat, 7 Sep 2024 05:25:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <vbgo4o$17c61$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 07 Sep 2024 07:25:48 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1890f914c1703e0604d6edeadffbf5ce";
logging-data="1290433"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8JLhGV+g1PzKyCLpvkbWD"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:xiBxUhzXjsdbUx+UHC4KQW+NigM=
View all headers

Edward Fagan wrote:

> Something like this function will tell you the position of
> the last comma in a string.
>
> (defun find-last-comma (s)
> (loop for n from 0 below (length s)
> if (char= (aref s n) #\,)
> do
> (if (and (loop for n downfrom (1- (length s)) to 0
> if (char= (aref n s) #\,)
> return n
> finally (return nil))
> (= n (loop for n downfrom (1- (length s)) to 0
> if (char= (aref s n) #\,)
> return n
> finally (return nil))))
> (return-from find-last-coma n))
> finally (return nil)))

Testing in SBCL:

* (FIND-LAST-COMMA "hi, hi, ho")

debugger invoked on a SIMPLE-TYPE-ERROR in thread
#<THREAD "main thread" RUNNING {23EAC201}>:
Value of N in (AREF N S) is 9, not a ARRAY.

Gauche Scheme

(string-scan-right "hi, hi, ho" #\,)
===>
6

(string-scan-right "hi, hi, ho" #\, 'before)
===>
"hi, hi"

(string-scan-right "hi, hi, ho" #\, 'after)
===>
" ho"

1

rocksolid light 0.9.8
clearnet tor