From: Juan Pardillos
Subject: List to string conserving the case.
Date: 
Message-ID: <6278687.0205120405.4d1cbd48@posting.google.com>
Hello,

I need a Lisp function to convert a list into a string. The problem is that
I want to conserve the case.

E.g.:

(toString '("A" "b" "C")) -> "AbC"

If it is possible I'd like that this also works when elements are atoms:

(toString '(A b C)) -> "AbC"

Any ideas?.

Please, help.

From: Karsten Poeck
Subject: Re: List to string conserving the case.
Date: 
Message-ID: <ablr9q$mu1$1@news.wanadoo.es>
Hola,
For strings easy, but for symbols not possible, because the reader converts
them  AFAIK
(defun list2string (list)
  (apply #'concatenate 'string (mapcar #'(lambda(a)
                                           (if (stringp a)
                                               a
                                             (if (symbolp a)
                                                 (symbol-name a)
                                               (princ-to-string a))))
                                 list)))

(list2string '("But" "This" "is" not Possible (for symbols) "only for
strings"))
->
 "ButThisisNOTPOSSIBLE(FOR SYMBOLS)only for strings"

"Juan Pardillos" <·······@eresmas.com> wrote in message
································@posting.google.com...
> Hello,
>
> I need a Lisp function to convert a list into a string. The problem is
that
> I want to conserve the case.
>
> E.g.:
>
> (toString '("A" "b" "C")) -> "AbC"
>
> If it is possible I'd like that this also works when elements are atoms:
>
> (toString '(A b C)) -> "AbC"
>
> Any ideas?.
>
> Please, help.
From: Christian Nyb�
Subject: Re: List to string conserving the case.
Date: 
Message-ID: <87y9ep76s9.fsf@nybo.no>
"Karsten Poeck" <······@terra.es> writes:

> For strings easy, but for symbols not possible, because the reader
> converts them AFAIK

Tell the reader that you want it to preserve case, then:

CL-USER(7): (list2string '("But" "This" "is" |not| |Possible| (|for|
|symbols|) "only for strings"))

"ButThisisnotPossible(for symbols)only for
strings"
CL-USER(8):

Documented in
http://www.xanalys.com/software_tools/reference/HyperSpec/Body/02_ade.htm
-- 
chr
From: Kaz Kylheku
Subject: Re: List to string conserving the case.
Date: 
Message-ID: <O4AD8.12222$a04.56145@tor-nn1.netcom.ca>
On 12 May 2002 05:05:45 -0700, Juan Pardillos <·······@eresmas.com> wrote:
>Hello,
>
>I need a Lisp function to convert a list into a string. The problem is that
>I want to conserve the case.
>
>E.g.:
>
>(toString '("A" "b" "C")) -> "AbC"

There is no special problem here. Strings preserve case; catenating
them does also.

One approach:

(defun to-string (list)
  (reduce #'(lambda (x &optional y) 
	     (concatenate 'string x y)) 
	  list :initial-value ""))

>If it is possible I'd like that this also works when elements are atoms:
>
>(toString '(A b C)) -> "AbC"

The Lisp reader converts your printed symbols names A b C to A B C; the lower
case is lost as your program source is scanned. Without hacking the reader, the
above is simply impossible.

The consequence of folding to upper case is that a symbol name like "FOO" has
many printed representations, among them:

    Foo FOO fOO FoO |FOO| \F\O\O

Yet, it is possible to have a symbol whose name is "Foo".  Lisp has escape
notations to suppress the conversion to upper case, giving rise to these
printed representations of "Foo", among others:

    |Foo|  f|oo|   f\o\o   f\o|o|

To handle symbols and other atoms, we might rewrite to-string like
this:

(defun to-string (list)
  (reduce #'(lambda (x &optional (y "")) 
	     (format nil "~a~a" x y)) 
	  list :initial-value ""))

I used the name to-string, because toString is really the symbol whose name is
"TOSTRING". Multi-capitalized identifiers are not useful in Lisp, because the
case information is lost. Even if you consistently follow your convention, your
Lisp system will not quote it back to you.  It is better to adopt the
convention of using dashes to separate the elements of compound identifiers.
From: Kalle Olavi Niemitalo
Subject: Re: List to string conserving the case.
Date: 
Message-ID: <87vg9t6xt1.fsf@Astalo.y2000.kon.iki.fi>
·······@eresmas.com (Juan Pardillos) writes:

> I need a Lisp function to convert a list into a string.

See the Common Lisp Cookbook:
http://cl-cookbook.sourceforge.net/strings.html#concat