Deutsch English Français Italiano |
<vbgo4o$17c61$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!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: 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= Bytes: 1962 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"