[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Issue: READ-CASE-SENSITIVITY (Version 2)
- To: Jeff Dalton <jeff%aiai.edinburgh.ac.uk@NSS.Cs.Ucl.AC.UK>
- Subject: Re: Issue: READ-CASE-SENSITIVITY (Version 2)
- From: peck@Sun.COM
- Date: Fri, 24 Mar 89 13:45:27 PST
- Cc: CL-Cleanup@sail.stanford.edu
- In-reply-to: Your message of Fri, 24 Mar 89 16:01:12 +0000; <2935.8903241601@subnode.aiai.ed.ac.uk> .
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.