Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

An optimist believes we live in the best world possible; a pessimist fears this is true.


devel / comp.lang.lisp / Subject: can't extract the digit-char?

SubjectAuthor
o Subject: can't extract the digit-char?Robert L.

1
Subject: can't extract the digit-char?

<svhv7i$t7j$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!6IAKdAn3fzHvPoP8SGYf0Q.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: Subject: can't extract the digit-char?
Date: Mon, 28 Feb 2022 07:56:36 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <svhv7i$t7j$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="29939"; posting-host="6IAKdAn3fzHvPoP8SGYf0Q.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Mon, 28 Feb 2022 07:56 UTC

> > Why the following code can't extract the digit-char?
> >
> > (with-input-from-string (is "abc def 777 a b c")
> > (loop
> > :for c := (read-char is nil 'the-end)
> > :while (digit-char-p c)
> > :collect c))
> >
> > What I expect result is (#\7 #\7 #\7), however I just get NIL.
> >
> > Cannot understand why?
> >
> > Regards,
> > Jinsong
>
>
> Because you confuse :while with :when:
>
> (with-input-from-string (is "abc def 777 a b c")
> (loop
> :for c := (read-char is nil 'the-end)
> :while (not (eq c 'the-end))
> :when (digit-char-p c)
> :collect c))
>
> There is also no need to specify the end marker for read-char (the
> default nil makes for simpler and more readable code).
>
> Personally, I wouldn't even use with-input-from-string and read-char in
> this case; a simple (loop for c across ...) would be better.

Gauche Scheme and Racket:

(use srfi-42) ;; list-ec for Gauche
(use srfi-14) ;; character-sets for Gauche
or
(require srfi/42) ;; list-ec for Racket
(require srfi/14) ;; character-sets for Racket

(list-ec (:string c "abc 0 def 67 7 a 7 b c")
(if (char-set-contains? char-set:digit c))
c)

===>
(#\0 #\6 #\7 #\7 #\7)


devel / comp.lang.lisp / Subject: can't extract the digit-char?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor