I would like to convert an atom to a string to check if the first letter is a capital letter but with Clisp the function string returns uppercase letters si I can't apply it to my atom.
Example :
(setq a 'ljlkj)
(upper-case-p (char (string a) 0)) ----> returns T (and I want nil)
What I am doing wrong?
Thanks you in advance!
Common Lisp reader is case-converting (step 7) by default.
This is controlled by the accessor readtable-case
:
(defun test-readtable-case-reading ()
(let ((*readtable* (copy-readtable nil)))
(format t "READTABLE-CASE Input Symbol-name~
~%-----------------------------------~
~%")
(dolist (readtable-case '(:upcase :downcase :preserve :invert))
(setf (readtable-case *readtable*) readtable-case)
(dolist (input '("ZEBRA" "Zebra" "zebra"))
(format t "~&:~A~16T~A~24T~A"
(string-upcase readtable-case)
input
(symbol-name (read-from-string input)))))))
The output from (test-readtable-case-reading)
should be as follows:
READTABLE-CASE Input Symbol-name
-------------------------------------
:UPCASE ZEBRA ZEBRA
:UPCASE Zebra ZEBRA
:UPCASE zebra ZEBRA
:DOWNCASE ZEBRA zebra
:DOWNCASE Zebra zebra
:DOWNCASE zebra zebra
:PRESERVE ZEBRA ZEBRA
:PRESERVE Zebra Zebra
:PRESERVE zebra zebra
:INVERT ZEBRA zebra
:INVERT Zebra Zebra
:INVERT zebra ZEBRA
See the excellent answer to Why is Common Lisp case insensitive? for the reasons why the CL reader is case-converting.