From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.stueberl.de!news.netway.at!nmaster.kpnqwest.net!nnum.kpnqwest.net!EU.net!nreader2.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: (setf (readtable-case *readtable*) :invert) completely preserves symbol case in CMUCL References: <3231416000515693@naggum.net> Mail-Copies-To: never From: Erik Naggum Message-ID: <3231423721764115@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 67 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 26 May 2002 17:42:04 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader2.kpnqwest.net 1022434924 193.71.199.50 (Sun, 26 May 2002 19:42:04 MET DST) NNTP-Posting-Date: Sun, 26 May 2002 19:42:04 MET DST Xref: archiver1.google.com comp.lang.lisp:33949 * Adam Warner | Yes I have achieved enlightenment Erik. You made my day! | I can't use preserve because none of the built in functions can be called | using lower case. Perhaps a custom compiled CMUCL image would be a long | term solution. Well, that way lies madness. One Common Lisp vendor has decided to make a "custom" world in which symbols are in their preferred lower-case. While I also like to read and see lower-case, all I need to do to get that most of the time is with either :invert or :upcase and *print-case* to :downcase. However, if you want to use lower-case names in your own code, you can shadow intern, find-symbol, and symbol-name to invert their argument. Efficient invertion is not necessarily a trivial task, and your implementation may have optimized functions for it, but this is a shot, and intended to be an efficien tone. Just how efficient it is seems to vary a lot between implementations: (defun invert-string (string) (declare (optimize (speed 3) (safety 0)) (simple-string string)) (check-type string 'string) (prog ((invert nil) (index 0) (length (length string))) (declare (simple-string invert) (type (integer 0 65536) index length)) unknown-case (cond ((= index length) (return string)) ((upper-case-p (schar string index)) (when (and (/= (1+ index) length) (lower-case-p (schar string (1+ index)))) (return string)) (setq invert (copy-seq string)) (go upper-case)) ((lower-case-p (schar string index)) (setq invert (copy-seq string)) (go lower-case)) (t (incf index) (go unknown-case))) upper-case (setf (schar invert index) (char-downcase (schar invert index))) (incf index) (cond ((= index length) (return invert)) ((lower-case-p (schar invert index)) (return string)) (t (go upper-case))) lower-case (setf (schar invert index) (char-upcase (schar invert index))) (incf index) (cond ((= index length) (return invert)) ((upper-case-p (schar invert index)) (return string)) (t (go lower-case))))) -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief. 70 percent of American adults do not understand the scientific process.