The reader will by default internalize symbols. Note that both the reader and printer affect how symbols are used and appear. If you want to see the real case of a symbol call (symbol-name some-symbol)
. The printer will try to escape a symbol if necessary, such that it can be read back and the same case gets used.
CL-USER 26 > 'foo
FOO
CL-USER 27 > 'f\oo
|FoO|
CL-USER 28 > (symbol-name 'f\oo)
"FoO"
The reader allows the control of how a symbol gets read. See below.
A few things to know:
all symbols are by default uppercase internally. By default the reader uppercases lowercase characters.
a symbol can contain arbitrary characters, including lowercase characters. The symbol then needs to use escapes:
Example:
|This is a valid symbol.|
Not that the vertical bars are not part of the symbol name. They are used to escape the symbol. Another escape character is the backslash:
1\a2
Above is also a symbol.
- note that things that contain numbers or characters can also be symbols or numbers, depending on the read base:
Example:
00a
Above is a symbol in the reader base 10.
Same Example, other read base:
00a
Above is a number in the reader base 16.
- a non-interned symbol (not in a package) is written like this:
Example:
#:non-interned-symbol
- a keyword symbol:
Example:
:keyword-symbol
How can you influence in which case a symbol is created/looked-up during read?
you can escape the symbol, see above
Use a readtable with a different case.
Example in the Common Lisp Hyperspec: 23.1.2.1 Examples of Effect of Readtable Case on the Lisp Reader
Turn off escaping in the printer
CL-USER 36 > (let ((*print-escape* nil))
(write (read-from-string "(|passWord| 000006013H)")))
(passWord 000006013H)
...