• Re: Use of format or pprint

    From B. Pym@21:1/5 to All on Tue Jul 2 18:44:00 2024
    Here are some functions I've written to convert strings into
    lists of various sorts. Examples follow at the end.

    (defun list-from-string (string
    &key
    (start 0)
    (char-bag '(#\Space))
    (test #'(lambda (ch)
    (not (member ch char-bag
    :test 'char=))))
    (post-process 'identity))
    (let ((pos (position-if test string :start start)))
    (if pos
    (list-from-string* string :start pos :char-bag char-bag
    :test test :post-process post-process)
    nil)))

    (defun list-from-string* (string
    &key
    (start 0)
    (char-bag '(#\Space))
    (test #'(lambda (ch)
    (not (member ch char-bag :test 'char=))))
    (post-process 'identity))
    (let* ((pos (position-if-not test string :start start))
    (new-pos (if pos (position-if test string :start pos) nil)))
    (cond
    ((and pos new-pos)
    (cons (funcall post-process (subseq string start pos))
    (list-from-string* string :start new-pos :char-bag char-bag
    :test test :post-process post-process)))
    (pos (list (funcall post-process (subseq string start pos))))

    (t (list (funcall post-process (subseq string start)))))))
    ....
    (list-from-string "chris! dan! ski! elaine! nick!"
    :char-bag '(#\Space #\!)) -->
    ("chris" "dan" "ski" "elaine" "nick")

    Gauche Scheme

    (use srfi-13)
    (use srfi-14)

    (string-tokenize
    " chris!..?..!dan!ski!;elaine! nick! "
    char-set:letter)

    ===>
    ("chris" "dan" "ski" "elaine" "nick")

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