Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Beware of programmers carrying screwdrivers." -- Chip Salzenberg


devel / comp.lang.lisp / String processing

SubjectAuthor
o String processingRobert L.

1
String processing

<t27mgh$6hc$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!lNWn9cxTR/GpcgzEu9WJbg.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: String processing
Date: Fri, 1 Apr 2022 20:15:16 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t27mgh$6hc$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="6700"; posting-host="lNWn9cxTR/GpcgzEu9WJbg.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. - Fri, 1 Apr 2022 20:15 UTC

Pierre Mai wrote:

> > We've had this discussion before. Perl was designed to make file scanning
> > and pattern matching easy. The programs we've been designing in this
> > thread are precisely the kind of application that Perl is intended for.
> > I'm well-enough versed in Lisp to know that the equivalent of:
> >
> > while (<>) { # Loop over input lines
> > counter++ if /^\s*\(/; # if first non-white character is open-paren, count i
> t
> > }
> >
> > would be much more verbose without being significantly more expressive.
> -------------
>
> If it weren't for the regexp, which needs a comment of 10 words to
> explain what it does, and which is easy to get wrong (either comment,
> or regexp that is), I could believe that statement, but so I have to
> humbly disagree ;)
>
> Anyways, this is Common Lisp:
>
> (loop for line = (read-line *standard-input* nil nil)
> while line
> count (starts-with (left-trim-whitespace line) "("))
>
> This uses two trivial string functions which are probably part of
> every working CL user[1]. With an extensible LOOP facility, this could
> even be clarified further...
.....
> Footnotes:
> [1] Here are some very simple, inefficient sample implementations:
> (defun starts-with (string substring)
> "Detect whether the `string' starts with `substring'."
> (eql 0 (search substring string)))
>
> (defun left-trim-whitespace (string &optional (ws-bag '(#\Space #\Tab)))
> "Trims any whitespace characters (i.e. characters in `ws-bag') from
> the left side of `string'."
> (string-left-trim ws-bag string))

Gauche Scheme or Racket.

(use srfi-13) ; string functions for Gauche
(use srfi-42) ; sum-ec for Gauche
or
(require srfi/13) ; string functions for Racket
(require srfi/42) ; sum-ec for Racket

(sum-ec (:port line (current-input-port) read-line)
(if (string-prefix? "(" (string-trim line)))
1)

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor