Deutsch English Français Italiano |
<v7048c$2u3o$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" <Nobody447095@here-nor-there.org> Newsgroups: comp.lang.lisp Subject: Join Date: Sun, 14 Jul 2024 09:03:11 -0000 (UTC) Organization: A noiseless patient Spider Lines: 29 Message-ID: <v7048c$2u3o$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Sun, 14 Jul 2024 11:03:11 +0200 (CEST) Injection-Info: dont-email.me; posting-host="2af9a93e51c2354c9c01f27f8d2b9bf3"; logging-data="96376"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XSUsuf3rpARGezJkFa1eS" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:AJcOe1Lm3AA7ZHcrgVIzLO40fk0= Bytes: 1600 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)))))