Re: Extended loop macro

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Extended loop macro
De : No_spamming (at) *nospam* noWhere_7073.org (B. Pym)
Groupes : comp.lang.lisp
Date : 05. Jul 2024, 05:40:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v67puc$34oek$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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

Date Sujet#  Auteur
5 Jul 24 o Re: Extended loop macro1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal