Join

Liste des GroupesRevenir à cl lisp 
Sujet : Join
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 14. Jul 2024, 10:03:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v7048c$2u3o$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Adam Warner wrote:

Hi Lowell Kirsh,
 
I want to write a function to take a list of strings and a delimiter and
return a string with the strings put together with the delimiter as glue.
 
e.g. (join '("foo" "bar" "baz")) -> "foo:bar:baz"
 
(defun join (list &optional (delimiter #\:))
  (let ((countdown (length list)))
    (with-output-to-string (stream)
      (dolist (item list)
        (write-string item stream)
        (decf countdown)
        (unless (zerop countdown)
          (write-char delimiter stream))))))

Gauche Scheme

(define (join lst :optional (delimiter #\,))
  (with-output-to-string
    (lambda()
      (display (car lst))
      (for-each
        (cut format #t "~a~a" delimiter <>)
        (cdr lst)))))



Date Sujet#  Auteur
14 Jul 24 o Join1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal