Skip to content

Instantly share code, notes, and snippets.

@zhouqiang-cl
Last active December 3, 2016 16:26
Show Gist options
  • Save zhouqiang-cl/525e7e3d022e6fc3583d23cd8629a230 to your computer and use it in GitHub Desktop.
Save zhouqiang-cl/525e7e3d022e6fc3583d23cd8629a230 to your computer and use it in GitHub Desktop.
common lisp 中的readtable case 对lisp reader的影响
描述
current readtable 的 readtable 有以下几个 case 会影响 lisp reader
:upcase
当 readtable 的 case 为 upcase 时, 字符都会被转化成 uppercase
:downcase
当 readtable 的 case 为 downcase 时, 字符都会被转化成 lowercase
:preserve
所见即所得
:invert
     当这个 token 所有字符的 case 相同的时候, 会被转化成对立的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)))))))
TEST-READTABLE-CASE-READING
* (test-readtable-case-reading)
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
NIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment