Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

He hath eaten me out of house and home. -- William Shakespeare, "Henry IV"


comp / comp.lang.lisp / Re: Extended loop macro

SubjectAuthor
o Re: Extended loop macroB. Pym

1
Subject: Re: Extended loop macro
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Fri, 5 Jul 2024 03:40 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Extended loop macro
Date: Fri, 5 Jul 2024 03:40:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <v67puc$34oek$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 05 Jul 2024 05:40:01 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="11bd25c943d4777aa7993dde8ec0a313";
logging-data="3301844"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/T9NvVJLW/oDhZ03VpzSSq"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:FYWTbWtWujdwxCfsNLpkAJm+7i0=
View all headers

Antonio Menezes Leitao wrote:

> Edi Weitz <spamt...@agharta.de> writes:
> > (loop with scheme-char-seen-p = nil
> > for c across string
> > when (or (char-not-greaterp #\a c #\z)
> > (digit-char-p c)
> > (member c '(#\+ #\- #\.) :test #'char=))
> > do (setq scheme-char-seen-p t)
> > else return (and scheme-char-seen-p
> > (char= c #\:)))
>
> Lot's of extremely nice examples! And the last one even ends with a
> smile. I hope you can see it!
>
> Thanks a lot,

In other words, test whether the string begins with a
sequence composed of a-z, 0-9, or [.+-], followed
by ":".

"char-not-greaterp" looks like a joke, doesn't it?
If you think it's Intercal, but it's not, it's
Common Lisp.

The easiest way would be to use regular expressions.
Let's do it a harder way.

Gauche Scheme

(use srfi-13) ;; string functions
(use srfi-14) ;; character sets

(define ch-set
(char-set-union
char-set:lower-case
char-set:digit
(string->char-set ".+-")))

(define (foo str)
(let ((i (string-index str (char-set-complement ch-set)))
(j (string-index str #\:)))
(and i j (> i 0) (= i j))))

(foo " hello")
#f

(foo "hello")
#f

(foo ": hello")
#f

(foo "abc: hello")
#t

(foo ".+-: hello")
#t

1

rocksolid light 0.9.8
clearnet tor