D Herring <dherring@at.tentpost.dot.com> wrote:
+---------------
| Rob Warnock wrote:
| > Doing (setf (readtable-case *readtable*) :invert) will do much the
| > name thing, but without losing information in case you have some
| > mixed-case symbols in your environment.
|
| True, but :invert is a braindead, clever hack by people who refuse to
| move forward with life. I don't much like it, but don't see anything
| better without changing CL's core. And it doesn't even work all the
| time; try typing a cl: symbol with CamelCase...
+---------------
I'm not sure what you mean by "doesn't even work all the time".
It works as documented in the CLHS:
23.1.2 Effect of Readtable Case on the Lisp Reader
...
:invert
When the readtable case is :invert, then if all of the
unescaped letters in the extended token are of the same case,
those (unescaped) letters are converted to the opposite case.
and:
22.1.3.3.2 Effect of Readtable Case on the Lisp Printer
...
:invert
When the readtable case is :invert, the case of all
alphabetic characters in single case symbol names is
inverted. Mixed-case symbol names are printed as is.
To wit:
> (readtable-case *readtable*)
:UPCASE
> (setf (readtable-case *readtable*) :invert)
:invert
> (defun show (sym)
(list sym (symbol-name sym)))
show
> (show 'cl::foo)
(common-lisp::foo "FOO")
> (show 'cl::FooBar)
(common-lisp::FooBar "FooBar")
> (show 'cl::FOO)
(common-lisp::FOO "foo")
>
Now you might not *like* the documented behavior, but it's useful
when one needs to read sexps from files written in CamelCase [e.g.,
EDIF files] when what one mostly wants is read/print invariance
together with the ability to still input symbols in the CL package
in lowercase.
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607