• Re: Extended loop macro

    From B. Pym@21:1/5 to Antonio Menezes Leitao on Fri Jul 5 03:40:01 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)