[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: ?



Hi Anton,

SRFI-6 ... :o))

By the way: Here is - tataaa - another and even shorter and much nicer
string->wordlist - function. Or did I forget about SRFI-2341 and
SRFI-2090775 ?

;; Abbreviations:
;;     WRD and W:  Word-Constructing-Robots
;;     LST and L:  List-Constructing-Robots
;;     iw:         in-word-flag
(define (STRING->WORDLIST str)
  (let ((WRD (lambda (x) (list->string x)))
        (LST (lambda (x) x)))
    (let FUN ((ls (string->list str))
              (L LST)
              (W WRD)
              (iw #f))
      (if (pair? ls)
          (if iw
              (if (char-whitespace? (car ls))
                  (FUN (cdr ls) 
                       (lambda (x) (L (cons (W '() ) x)))
                       WRD
                       #f)
                  (FUN (cdr ls)
                       L
                       (lambda (x) (W (cons (car ls) x)))
                       #t))
              (if (char-whitespace? (car ls))
                  (FUN (cdr ls)
                       L
                       W
                       #f)
                  (FUN (cdr ls)
                       L
                       (lambda (x) (WRD (cons (car ls) x)))
                       #t)))
          (L (list (W '() )))))))

(string->wordlist 
 "This function is interfering with your natural selection")

=>

("This" "function" "is" "interfering" "with" "your" "natural"
"selection")