From: Christian Lynbech
Subject: format question
Date: 
Message-ID: <oflljdj8r2.fsf@situla.ted.dk.eu.ericsson.se>
I frequently run into the problem of having to format a list of values
into a string with some delimiters in between the values. My usual
approach is something like this:

    (let ((odds '(1 3 5 7 9)))
      (format nil "(~A~{,~A~})" (car odds) (cdr odds)))

in order to get the desired string of:

    "(1,3,5,7,9)"

Given the amazing power of 'format', can it really be that there isn't
a more elegant solution?


------------------------+-----------------------------------------------------
Christian Lynbech       | christian ··@ defun #\. dk
------------------------+-----------------------------------------------------
Hit the philistines three times over the head with the Elisp reference manual.
                                        - ·······@hal.com (Michael A. Petonic)

From: mrd
Subject: Re: format question
Date: 
Message-ID: <Pine.LNX.4.58-035.0405281803460.7165@unix45.andrew.cmu.edu>
On Fri, 28 May 2004, Christian Lynbech wrote:
> I frequently run into the problem of having to format a list of values
> into a string with some delimiters in between the values. My usual
> approach is something like this:
>
>     (let ((odds '(1 3 5 7 9)))
>       (format nil "(~A~{,~A~})" (car odds) (cdr odds)))
>
> in order to get the desired string of:
>
>     "(1,3,5,7,9)"
>
> Given the amazing power of 'format', can it really be that there isn't
> a more elegant solution?

(format nil "(~{~A~^,~})" odds).  ~^ means escape if no more elements.
See CLHS for examples of more complicated lists, such as a proper English
list with 'and' or 'or'.
From: Edi Weitz
Subject: Re: format question
Date: 
Message-ID: <87wu2wnorq.fsf@bird.agharta.de>
On Fri, 28 May 2004 09:44:49 +0200, Christian Lynbech <·················@ericsson.com> wrote:

> I frequently run into the problem of having to format a list of
> values into a string with some delimiters in between the values. My
> usual approach is something like this:
>
>     (let ((odds '(1 3 5 7 9)))
>       (format nil "(~A~{,~A~})" (car odds) (cdr odds)))
>
> in order to get the desired string of:
>
>     "(1,3,5,7,9)"
>
> Given the amazing power of 'format', can it really be that there
> isn't a more elegant solution?

This is starting to become an FAQ. Third time in less than two
months... :)

Cheers,
Edi.

PS: I see you already got an answer so I won't bother you with that.