Subject: Re: reading symbols preserving case
From: (Rob Warnock)
Date: Thu, 02 Apr 2009 06:07:47 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Francisco Vides Fernández  <> wrote:
| I'm trying to write something like this:
| (case-preserving-context
|   (a list of symbols))
| => 
| (|a| |list| |of| |symbols|)
| Which basically setf the readtable-case of *readtable* to :preserve ...
| but I'd like something cleaner, if possible. Some suggestions?

Others have given you good answers, but depending on exactly what
you're trying to accomplish, you might want to take a close look
at :INVERT rather than :PRESERVE. Assuming your source code is all
lowercase, you can (setf (readtable-case *readtable*) :invert) and
*leave* it that way, and still preserve CamelCase:

    > (readtable-case *readtable*)

    > 'foo

    > (setf (readtable-case *readtable*) :invert)

    > 'foo

    > '(A List Of Symbols such as FOO & BAR)

    (A List Of Symbols such as FOO & BAR)
    > (mapcar #'symbol-name *)	; Show the "real" internal case

    ("a" "List" "Of" "Symbols" "SUCH" "AS" "foo" "&" "bar")
    > (eq 'foo (intern "FOO"))	; So lowercase source code works

    > (eq 'FOO (intern "FOO"))	;   but uppercase source doesn't,

    > (eq 'FOO (intern "foo"))	;   unless you really do want lowercase names.


When readtable-case is :INVERT, the printer also inverts on output
by default. If all you need is read/print invariance of case, :INVERT
may be your friend.


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607