Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Vulcans do not approve of violence. -- Spock, "Journey to Babel", stardate 3842.4


devel / comp.lang.lisp / Re: breaking strings

SubjectAuthor
* breaking stringsJames Cloos
+* Re: breaking stringsJeff Barnett
|`- Re: breaking stringsJeff Barnett
+* Re: breaking stringsMadhu
|`- Re: breaking stringsMadhu
+* Re: breaking stringsSpiros Bousbouras
|`* Re: breaking stringsRalph Schleicher
| `* Re: breaking stringsRaymond Wiker
|  `- Re: breaking stringsMadhu
`* Re: breaking stringsZyni Moë
 `- Re: breaking stringsZyni Moë

1
breaking strings

<m38rp654ra.fsf@carbon.jhcloos.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17143&group=comp.lang.lisp#17143

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: cloos@jhcloos.com (James Cloos)
Newsgroups: comp.lang.lisp
Subject: breaking strings
Date: Wed, 06 Jul 2022 17:07:53 -0400
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <m38rp654ra.fsf@carbon.jhcloos.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="2b2f43b4b81945682b9856dcc49f0e33";
logging-data="156049"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PQGvwNPoJYK5EXWMOhfa4"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cancel-Lock: sha1:PEuZ2xgIHAKfGkoMj1jJ/US0LnM=
sha1:vjxs+/Dce/vdmeCnlaHSUs1xjtw=
OpenPGP: 0x997A9F17ED7DAEA6; url=https://jhcloos.com/public_key/0x997A9F17ED7DAEA6.asc
Copyright: Copyright 2022 James Cloos
OpenPGP-Fingerprint: E9E9 F828 61A4 6EA9 0F2B 63E7 997A 9F17 ED7D AEA6
Face: iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAgMAAABinRfyAAAACVBMVEX///8ZGXBQKKnCrDQ3
AAAAJElEQVQImWNgQAAXzwQg4SKASgAlXIEEiwsSIYBEcLaAtMEAADJnB+kKcKioAAAAAElFTkSu
QmCC
 by: James Cloos - Wed, 6 Jul 2022 21:07 UTC

what is the best way to take a string with inegers interspersed with
non-integer chars and split it into a list of integers and chars?

in my particular case the ints are all (supposed to be) non-neg.
and there should be at most one non-digit-p char between ints.

i've looked into cycling thru with parse-integer for the ints, grabbing
the next char (if any) and looping like that until the string is done.

or looping across the string, builing up ints via (+(* 10 ..)..).

is there a better way?

i'm avoiding external libs for this code, so i need to do this w/o using
cl-ppcre or the like...

thanks,

-JimC
--
James Cloos <cloos@jhcloos.com> OpenPGP: 0x997A9F17ED7DAEA6

Re: breaking strings

<ta4vqe$52dh$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17144&group=comp.lang.lisp#17144

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!news.freedyn.de!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: jbb@notatt.com (Jeff Barnett)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Wed, 6 Jul 2022 15:45:47 -0600
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ta4vqe$52dh$1@dont-email.me>
References: <m38rp654ra.fsf@carbon.jhcloos.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 6 Jul 2022 21:45:51 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="a655a12fd9588f3c2032b135adf279f2";
logging-data="166321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BoxTo/ii3WPukmnpiSBCvPdgZqPWBVhE="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Cancel-Lock: sha1:dFyhim6XSZtnI7ccBD1Z4gh8y1U=
Content-Language: en-US
In-Reply-To: <m38rp654ra.fsf@carbon.jhcloos.org>
 by: Jeff Barnett - Wed, 6 Jul 2022 21:45 UTC

On 7/6/2022 3:07 PM, James Cloos wrote:
> what is the best way to take a string with inegers interspersed with
> non-integer chars and split it into a list of integers and chars?
>
> in my particular case the ints are all (supposed to be) non-neg.
> and there should be at most one non-digit-p char between ints.
>
> i've looked into cycling thru with parse-integer for the ints, grabbing
> the next char (if any) and looping like that until the string is done.
>
> or looping across the string, builing up ints via (+(* 10 ..)..).
>
> is there a better way?
>
> i'm avoiding external libs for this code, so i need to do this w/o using
> cl-ppcre or the like...
>
> thanks,

(loop for elm in list
when num-elm(elm) collect elm in num-list
else collect elm in other-list
finally return (values num-list other-list))
--
Jeff Barnett

Re: breaking strings

<ta4vsi$52dh$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17145&group=comp.lang.lisp#17145

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!news.freedyn.de!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: jbb@notatt.com (Jeff Barnett)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Wed, 6 Jul 2022 15:46:56 -0600
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <ta4vsi$52dh$2@dont-email.me>
References: <m38rp654ra.fsf@carbon.jhcloos.org> <ta4vqe$52dh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: base64
Injection-Date: Wed, 6 Jul 2022 21:46:58 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="a655a12fd9588f3c2032b135adf279f2";
logging-data="166321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//cZhH5L7aqbRLe81mVJ3/npgg+PSJ+No="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Cancel-Lock: sha1:FOYn1Al6cPhwB30npVxe8AyaYQM=
Content-Language: en-US
In-Reply-To: <ta4vqe$52dh$1@dont-email.me>
 by: Jeff Barnett - Wed, 6 Jul 2022 21:46 UTC

On 7/6/2022 3:45 PM, Jeff Barnett wrote:
> On 7/6/2022 3:07 PM, James Cloos wrote:
>> what is the best way to take a string with inegers interspersed with
>> non-integer chars and split it into a list of integers and chars?
>>
>> in my particular case the ints are all (supposed to be) non-neg.
>> and there should be at most one non-digit-p char between ints.
>>
>> i've looked into cycling thru with parse-integer for the ints, grabbing
>> the next char (if any) and looping like that until the string is done.
>>
>> or looping across the string, builing up ints via (+(* 10 ..)..).
>>
>> is there a better way?
>>
>> i'm avoiding external libs for this code, so i need to do this w/o using
>> cl-ppcre or the like...
>>
>> thanks,
>
> (loop for elm in list
>     when num-elm(elm) collect elm in num-list
>     else collect elm in other-list
>     finally return (values num-list other-list))
Sorry I misread the problem.
--
Jeff Barnett

Re: breaking strings

<m35yk91y8v.fsf@leonis4.robolove.meer.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17146&group=comp.lang.lisp#17146

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!news.freedyn.de!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Thu, 07 Jul 2022 07:26:48 +0530
Organization: Motzarella
Lines: 55
Message-ID: <m35yk91y8v.fsf@leonis4.robolove.meer.net>
References: <m38rp654ra.fsf@carbon.jhcloos.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="1fbc643a8d49a77d8ba02c80e555a50e";
logging-data="296703"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JLpcRH8nUl1VsX2GaaMwPZITn3MSeWjo="
Cancel-Lock: sha1:tUsYwMRvccvd9EIOqVIpJsw/cpA=
sha1:3t1DUWfCWBDY6P10kn22os8kpbY=
 by: Madhu - Thu, 7 Jul 2022 01:56 UTC

* James Cloos <m38rp654ra.fsf@carbon.jhcloos.org> :
Wrote on Wed, 06 Jul 2022 17:07:53 -0400:

> what is the best way to take a string with inegers interspersed with
> non-integer chars and split it into a list of integers and chars?
>
> in my particular case the ints are all (supposed to be) non-neg.
> and there should be at most one non-digit-p char between ints.
>
> i've looked into cycling thru with parse-integer for the ints, grabbing
> the next char (if any) and looping like that until the string is done.
>
> or looping across the string, builing up ints via (+(* 10 ..)..).
>
> is there a better way?
>
> i'm avoiding external libs for this code, so i need to do this w/o using
> cl-ppcre or the like...

Personally I'd do it with an external function.

```
(setq $s "foo 2030 29393 xyz 13 42 bar 666")

(let (a b) (string-split-map #(#\Space #\Tab) $s :map-fn (lambda (line p q) (if (digit-char-p (char line p)) (push (parse-integer line :start p :end q) a) (push (subseq line p q ) b)))) (list a b))

((666 42 13 29393 2030) ("bar" "xyz" "foo"))
```

with string-split-map from my lisp init file

```
(defun string-split-map (charbag line &key (start 0) end map-fn escape-char)
(let ((p start) (q 0) #+nil (i 0) ret (end (or end (length line))))
(declare (fixnum p q #+nil i))
(loop
;; skip whitespace at left
(loop (cond ((or (= p end) (or (not (find (elt line p) charbag))
(and escape-char (>= (1- p) start) (eql (elt line (1- p)) escape-char))))
(return))
(t (incf p))))
;; find word end
(setq q p)
(loop (cond ((and (< q end) (or (not (find (elt line q) charbag))
(and escape-char (>= (1- q) p) (eql (elt line (1- q)) escape-char))))
(incf q))
(t (return))))
(cond ((and (< p q))
(cond (map-fn (funcall map-fn line p q))
(t (push (subseq line p q) ret)))
(setq p q) #+nil
(incf i))
(t (return (nreverse ret)))))))
```

Re: breaking strings

<hs3Vs4knp=D3mqPvn@bongo-ra.co>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17147&group=comp.lang.lisp#17147

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Thu, 7 Jul 2022 03:51:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <hs3Vs4knp=D3mqPvn@bongo-ra.co>
References: <m38rp654ra.fsf@carbon.jhcloos.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 7 Jul 2022 03:51:23 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e0b10bc02698f8efc1ecad32b788a29";
logging-data="317963"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19m9kkxdJyhaL6DGW4br/4Q"
Cancel-Lock: sha1:2YPxpUFEgTEoPvyDrZtF1Rq/kXI=
In-Reply-To: <m38rp654ra.fsf@carbon.jhcloos.org>
X-Server-Commands: nowebcancel
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Thu, 7 Jul 2022 03:51 UTC

On Wed, 06 Jul 2022 17:07:53 -0400
James Cloos <cloos@jhcloos.com> wrote:
> what is the best way to take a string with inegers interspersed with
> non-integer chars and split it into a list of integers and chars?
>
> in my particular case the ints are all (supposed to be) non-neg.
> and there should be at most one non-digit-p char between ints.

Do you mean DIGIT-CHAR-P ? If instead of "at most one" of whatever there are
0 , how are the integers going to be separated ?

> i've looked into cycling thru with parse-integer for the ints, grabbing
> the next char (if any) and looping like that until the string is done.
>
> or looping across the string, builing up ints via (+(* 10 ..)..).
>
> is there a better way?

So you want "123a5t789i412v" to return the list
(123 #\a 5 #\t 789 #\i 412 #\v) , yes ? I would use PARSE-INTEGER .

> i'm avoiding external libs for this code, so i need to do this w/o using
> cl-ppcre or the like...

Re: breaking strings

<m3zghlzbxs.fsf@leonis4.robolove.meer.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17148&group=comp.lang.lisp#17148

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Thu, 07 Jul 2022 11:44:39 +0530
Organization: Motzarella
Lines: 63
Message-ID: <m3zghlzbxs.fsf@leonis4.robolove.meer.net>
References: <m38rp654ra.fsf@carbon.jhcloos.org>
<m35yk91y8v.fsf@leonis4.robolove.meer.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="65fda72b42cffc2b2a47af0bbdf82b9b";
logging-data="338276"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cHYCZDs9CKYnnOuxvrsWbWpz9jjWbp74="
Cancel-Lock: sha1:rFnO97AINzW8ptjtLhIa+YKga7s=
sha1:sImwOo6P4hx5sTYRrrqOwNTs/Mc=
 by: Madhu - Thu, 7 Jul 2022 06:14 UTC

* I <m35yk91y8v.fsf @leonis4.robolove.meer.net> :
Wrote on Thu, 07 Jul 2022 07:26:48 +0530:

> * James Cloos <m38rp654ra.fsf @carbon.jhcloos.org> :
> Wrote on Wed, 06 Jul 2022 17:07:53 -0400:
>
>> what is the best way to take a string with inegers interspersed with
>> non-integer chars and split it into a list of integers and chars?
>>
>> in my particular case the ints are all (supposed to be) non-neg.
>> and there should be at most one non-digit-p char between ints.
>>
>> i've looked into cycling thru with parse-integer for the ints, grabbing
>> the next char (if any) and looping like that until the string is done.
>>
>> or looping across the string, builing up ints via (+(* 10 ..)..).
>>
>> is there a better way?
>>
>> i'm avoiding external libs for this code, so i need to do this w/o using
>> cl-ppcre or the like...
>
> Personally I'd do it with an external function.
>
> ```
> (setq $s "foo 2030 29393 xyz 13 42 bar 666")
>
> (let (a b) (string-split-map #(#\Space #\Tab) $s :map-fn (lambda (line p q) (if (digit-char-p (char line p)) (push (parse-integer line :start p :end q) a) (push (subseq line p q ) b)))) (list a b))
>
> ((666 42 13 29393 2030) ("bar" "xyz" "foo"))
> ```
>
>
> with string-split-map from my lisp init file

Sorry, Like Jeff Barnett I misread the question too. You should have
given an example to make it clear. If as I understand there are no white
spaces in the string then I'd slightly modify string-split-map I posted
(now snipped)

```
(defun parse-cloos (line &key (start 0) end)
(let ((p start) i (q 0) ret (end (or end (length line))) retnum)
(loop
(setq i p)
(loop (cond ((or (= p end) (or (not (digit-char-p (elt line p)))))
(return))
(t (incf p))))
(if (> p i) (push (parse-integer line :start i :end p) retnum))
(setq q p)
(loop (cond ((and (< q end) (or (not (digit-char-p (elt line q)))))
(incf q))
(t (return))))
(cond ((and (< p q))
(push (subseq line p q) ret)
(setq p q))
(t (return (values (nreverse ret) (nreverse retnum))))))))

(setq $a "a123c4445c223")
(parse-cloos $a)
; => ("a" "c" "c"), (123 4445 223)
```

Re: breaking strings

<ta6rd6$dd7t$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17149&group=comp.lang.lisp#17149

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: no_email@invalid.invalid (Zyni Moë)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Thu, 7 Jul 2022 14:42:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <ta6rd6$dd7t$1@dont-email.me>
References: <m38rp654ra.fsf@carbon.jhcloos.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 7 Jul 2022 14:42:46 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="40d6eb6da50194d469da913640134303";
logging-data="439549"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xaor7ZwDO5qYZDDzL9JVH/T2YdZ0UVnw="
User-Agent: NewsTap/5.5 (iPad)
Cancel-Lock: sha1:4Yly8SvDD4LTdFZbQBFhAY/j4AM=
sha1:v3LyNoL5WBusLWZ+AEDfnctWg84=
 by: Zyni Moë - Thu, 7 Jul 2022 14:42 UTC

James Cloos <cloos@jhcloos.com> wrote:
> what is the best way to take a string with inegers interspersed with
> non-integer chars and split it into a list of integers and chars?
>

This assumes base 10, could be changed not to (digit-char-p). Obviously
would be better with some macrology on it.

(defun tok (s)
(let ((l (length s)))
(labels
((nak->num (nak n e b)
(if (null nak)
n
(nak->num (rest nak)
(+ n (* (first nak) e))
(* e b)
b)))
(toker (i nak tak)
(if (= i l)
(if (not (null nak))
(nreverse (cons (nak->num nak 0 1 10) tak))
(nreverse tak))
(let ((c (char s i)))
(cond ((digit-char-p c)
(toker (+ i 1) (cons (- (char-code c)
(load-time-value (char-code
#\0)))
nak)
tak))
((not (null nak))
(toker (+ i 1) '() (cons (nak->num nak 0 1 10) tak)))
(t (toker (+ i 1) nak (cons c tak))))))))
(toker 0 '() '()))))

> (tok "82abc12dkgdf")
(82 #\b #\c 12 #\k #\g #\d #\f)

--
the small snake

Re: breaking strings

<ta6rjc$de3v$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17150&group=comp.lang.lisp#17150

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: no_email@invalid.invalid (Zyni Moë)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Thu, 7 Jul 2022 14:46:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <ta6rjc$de3v$1@dont-email.me>
References: <m38rp654ra.fsf@carbon.jhcloos.org>
<ta6rd6$dd7t$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 7 Jul 2022 14:46:04 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="40d6eb6da50194d469da913640134303";
logging-data="440447"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Gma6bDgLWvjDetSjzXdoQzz8/tT2YM8o="
User-Agent: NewsTap/5.5 (iPad)
Cancel-Lock: sha1:7eI+Su+lYEePDILnl2Z9rIXEy8g=
sha1:cJCdBQhWKL4Vxkxeir/lRIr0vg4=
 by: Zyni Moë - Thu, 7 Jul 2022 14:46 UTC

Zyni Moë <no_email@invalid.invalid> wrote:
> [wrong thing]

Dirty that was buggy (lost char after num) this is right i think:

(defun tok (s)
(let ((l (length s)))
(labels
((nak->num (nak n e b)
(if (null nak)
n
(nak->num (rest nak)
(+ n (* (first nak) e))
(* e b)
b)))
(toker (i nak tak)
(if (= i l)
(if (not (null nak))
(nreverse (cons (nak->num nak 0 1 10) tak))
(nreverse tak))
(let ((c (char s i)))
(cond ((digit-char-p c)
(toker (+ i 1) (cons (- (char-code c)
(load-time-value (char-code
#\0)))
nak)
tak))
((not (null nak))
(toker (+ i 1) '() (list* c (nak->num nak 0 1 10)
tak)))
(t (toker (+ i 1) nak (cons c tak))))))))
(toker 0 '() '()))))

--
the small snake

Re: breaking strings

<8635fabsup.fsf@ralph-schleicher.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17152&group=comp.lang.lisp#17152

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rs+usenet@ralph-schleicher.de (Ralph Schleicher)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Sat, 09 Jul 2022 10:19:58 +0200
Organization: Ralph Schleicher
Lines: 41
Message-ID: <8635fabsup.fsf@ralph-schleicher.de>
References: <m38rp654ra.fsf@carbon.jhcloos.org>
<hs3Vs4knp=D3mqPvn@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="7049208dbc03a2b217fef0cf2e847d9c";
logging-data="1064083"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Lhtv7vJdD6KfS9OhYL17LfbTKPeTDmig="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux)
Cancel-Lock: sha1:diz+zmX/4QjI3lkjwgBUQJIW6tI=
sha1:GsMmfItEY7NqUPpXNr+2jy3gdho=
 by: Ralph Schleicher - Sat, 9 Jul 2022 08:19 UTC

Spiros Bousbouras <spibou@gmail.com> writes:

> So you want "123a5t789i412v" to return the list
> (123 #\a 5 #\t 789 #\i 412 #\v) , yes ? I would use PARSE-INTEGER .

(let ((string "123a5t789i412v"))
(let ((start 0) (end (length string)) char list)
(loop
(unless (< start end)
(return))
(setf char (aref string start))
(cond ((digit-char-p char)
(multiple-value-bind (int pos)
(parse-integer string :start start :junk-allowed t)
(push int list)
(setf start pos)))
(t
(push char list)
(incf start))))
(nreverse list)))
==> (123 #\a 5 #\t 789 #\i 412 #\v)

Or, if reading from a stream:

(ql:quickload "read-number")
(let ((string "123a5t789i412v"))
(with-input-from-string (stream string)
(let (char list)
(loop
(setf char (peek-char nil stream nil stream))
(when (eq char stream)
(return))
(push (if (digit-char-p char)
(read-number:read-integer stream)
(read-char stream))
list))
(nreverse list))))
==> (123 #\a 5 #\t 789 #\i 412 #\v)

--
Ralph

Re: breaking strings

<m2h73p49pk.fsf@MacBook-Pro.home>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17153&group=comp.lang.lisp#17153

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rwiker@gmail.com (Raymond Wiker)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Sun, 10 Jul 2022 11:07:35 +0200
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <m2h73p49pk.fsf@MacBook-Pro.home>
References: <m38rp654ra.fsf@carbon.jhcloos.org>
<hs3Vs4knp=D3mqPvn@bongo-ra.co> <8635fabsup.fsf@ralph-schleicher.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="cf7b352bedb825ac53a57d2c270ffc40";
logging-data="1421987"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KbqgTDILaTJu4FnmKIe3n"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin)
Cancel-Lock: sha1:uXAwZWKMR17KpmzdM8D5K35QOeQ=
sha1:xruVTD8JDUyS4fyfdN2FMNQW5OU=
 by: Raymond Wiker - Sun, 10 Jul 2022 09:07 UTC

Ralph Schleicher <rs+usenet@ralph-schleicher.de> writes:

> Spiros Bousbouras <spibou@gmail.com> writes:
>
>> So you want "123a5t789i412v" to return the list
>> (123 #\a 5 #\t 789 #\i 412 #\v) , yes ? I would use PARSE-INTEGER .
>
> (let ((string "123a5t789i412v"))
> (let ((start 0) (end (length string)) char list)
> (loop
> (unless (< start end)
> (return))
> (setf char (aref string start))
> (cond ((digit-char-p char)
> (multiple-value-bind (int pos)
> (parse-integer string :start start :junk-allowed t)
> (push int list)
> (setf start pos)))
> (t
> (push char list)
> (incf start))))
> (nreverse list)))
> ==> (123 #\a 5 #\t 789 #\i 412 #\v)

Using extended loop:

(defun extract-chars-and-integers (string)
(loop with limit = (1- (length string))
for pos = 0 then next-pos
while (<= pos limit)
for pair = (or (multiple-value-bind (num end)
(parse-integer string :start pos :junk-allowed t)
(when num
(cons num end)))
(cons (char string pos) (1+ pos)))
for (value . next-pos) = pair
collect value))

(defvar *test-string* "123a5t789i412v")

(extract-chars-and-integers *test-string*)
=> (123 #\a 5 #\t 789 #\i 412 #\v)

Re: breaking strings

<m3o7xrhjfe.fsf@leonis4.robolove.meer.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17154&group=comp.lang.lisp#17154

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: breaking strings
Date: Thu, 14 Jul 2022 19:42:53 +0530
Organization: Motzarella
Lines: 66
Message-ID: <m3o7xrhjfe.fsf@leonis4.robolove.meer.net>
References: <m38rp654ra.fsf@carbon.jhcloos.org>
<hs3Vs4knp=D3mqPvn@bongo-ra.co> <8635fabsup.fsf@ralph-schleicher.de>
<m2h73p49pk.fsf@MacBook-Pro.home>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="43cd3a1476eeb7c985a95fb02707e9c3";
logging-data="2881891"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ionRI6jKpqdbH2/zqrq3Tz5u5Uj6HJyc="
Cancel-Lock: sha1:MgYlO2oerTzqdDgIv0zkZIlLc3Y=
sha1:WrvdfRuRpTIlMZeU3ducanI1NPs=
 by: Madhu - Thu, 14 Jul 2022 14:12 UTC

* Raymond Wiker <m2h73p49pk.fsf @MacBook-Pro.home> :
Wrote on Sun, 10 Jul 2022 11:07:35 +0200:
> Ralph Schleicher <rs+usenet @ralph-schleicher.de> writes:
>
>> Spiros Bousbouras <spibou @gmail.com> writes:
>>
>>> So you want "123a5t789i412v" to return the list
>>> (123 #\a 5 #\t 789 #\i 412 #\v) , yes ? I would use PARSE-INTEGER .
>>
>> (let ((string "123a5t789i412v"))
>> (let ((start 0) (end (length string)) char list)
>> (loop
>> (unless (< start end)
>> (return))
>> (setf char (aref string start))
>> (cond ((digit-char-p char)
>> (multiple-value-bind (int pos)
>> (parse-integer string :start start :junk-allowed t)
>> (push int list)
>> (setf start pos)))
>> (t
>> (push char list)
>> (incf start))))
>> (nreverse list)))
>> ==> (123 #\a 5 #\t 789 #\i 412 #\v)
>
> Using extended loop:
>
> (defun extract-chars-and-integers (string)
> (loop with limit = (1- (length string))
> for pos = 0 then next-pos
> while (<= pos limit)
> for pair = (or (multiple-value-bind (num end)
> (parse-integer string :start pos :junk-allowed t)
> (when num
> (cons num end)))
> (cons (char string pos) (1+ pos)))
> for (value . next-pos) = pair
> collect value))
>
> (defvar *test-string* "123a5t789i412v")
>
> (extract-chars-and-integers *test-string*)
> => (123 #\a 5 #\t 789 #\i 412 #\v)

If there are no "strings" to be parsed from the input then
parse-integer may be overkill.

For your endless (no pun) LOOP entertainment, here is a slightly obscure
version with NCONC, which assumes nconc is implemented with
tail-consing.

```
(defun parse-cloos (string &key (radix 10))
(loop with tail-cons for c across string for d = (digit-char-p c radix)
nconc
(etypecase (car tail-cons)
((or null character)
(setq tail-cons (cons (if d d c) nil)))
(number
(cond (d (setf (car tail-cons) (+ d (* (car tail-cons) radix)))
nil)
(t (setq tail-cons (cons c nil))))))))

(equal (parse-cloos "123a5t789i412v") '(123 #\a 5 #\t 789 #\i 412 #\v))
```

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor