[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue: READ-CASE-SENSITIVITY (Version 2)



Assuming that my confusion about :invert is resolved offline,
I have another, more positive suggestion for getting CommonLisp
into the case-sensitive world:

 The biggest block that i've found to writting portable code
in the mixed/preserve case world is those times when you want
intern a symbol from a string.  If the string is either hard-coded
(as a prefix string or :conc-name) or as entered from a user with
a readline equivalent, then the application should have a means
of converting the string as the reader would.  I have found use
for the function (CASE-CONVERT-NAME <string>) which returns a 
string which would be the name of a symbol if <string> were read
by the reader.

;;; This definition returns mostly the correct value,
;;; but has numerous unwanted side-effects, 
;;; I.E. creates and interns a symbol, chokes on by colons, etc.
  (defun CASE-CONVERT-NAME (string)
    (symbol-name (read-from-string string)))

;;; this is much closer, with READTABLE-CASE-SENSITIVITY:READTABLE-KEYWORDS
  (defun CASE-CONVERT-NAME (string)
    (case (readtable-case-sensitivity *readtable*)
      (:preserve string)
      (:upcase  (string-upcase string))
      (:downcase (string-downcase string))
      (:invert  (string-invertcase string)) ;; uses char-invert-case?
    ))

;;; or this, with READTABLE-CASE-SENSITIVITY:READTABLE-FUNCTIONS
   (defun CASE-CONVERT-NAME (string)
      (map 'string (readtable-case-sensitivity *readtable*) string))

If we could have a function such as this in the, maybe folks
would use it: (intern (concatentate 'string
			(case-convert-name "foo-")
			(case-convert-name sym) )
		     pkg)
Instead of: (intern (concatentate 'string "FOO-" sym) pkg)

With this extra layer, writing protable code to case-sensitive lisp 
is very much easier.  The version i use even has an extra arguement
to control whether destructive (in-place) or copying conversion is done.