how do we make lisp input case sensitive?

All symbols are interned as upper case by default. When you write defun, it is read as DEFUN internally, for example, and that is the symbol with the symbol-name string "DEFUN".

There are two ways for ad hoc overriding this reading behaviour: you can escape single characters in symbols with \, or you can escape multiple characters by enclosing them in pipes |…|. Escaped characters are taken as they are entered, and can be any characters. |This is a valid symbol.| and its symbol-name is "This is a valid symbol.".

So, each of these becomes the symbol whose symbol-name is “Abc”:


Now, the printer prints symbols in such a way that when read in by the reader they are the same symbol. So, if there are any lower-case or non-constituent characters in the symbol name, they need to be escaped in one of the ways shown above. My SBCL uses the last option.

You can customize the read/print behaviour through the readtable. For example, you can set the readtable-case to :preserve:

(defun foo ()
  (let ((*readtable* (copy-readtable *readtable*)))
    (setf (readtable-case *readtable*) :preserve)
    (print (append (read) (read)))))

If you now run (foo), then enter (a b) and (A B), first (a b A B) is printed, and then the REPL prints the returned list as (|a| |b| A B) because we made sure to change only a lexically scoped copy of the actual readtable.

You can read up on this in the Hyperspec and play around with it a bit. If you have an actual problem to solve, we’ll have to see how to best address it.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top