Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #344: Network failure - call NBC


comp / comp.lang.lisp / Join

SubjectAuthor
o JoinB. Pym

1
Subject: Join
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 14 Jul 2024 09:03 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
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=
View all headers

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)))))

1

rocksolid light 0.9.8
clearnet tor