krovetz@cs.umass.edu (Bob Krovetz) (12/29/90)
I have a file of s-expressions that are in upper and lower case. I would like to read them, but keep the case intact (i.e., the s-expression would consist of atoms of the form |Foo|). These will then be converted into strings for subsequent processing. Can someone tell me how to do this? I believe I need to change the readtable, but it isn't clear to me what changes are necessary. The alternative is to read the file using READLINE and parse the information myself, but it would be nice to use the built-in parsing supplied by READ. Thanks, Bob krovetz@cs.umass.edu
barmar@think.com (Barry Margolin) (12/29/90)
In article <24437@dime.cs.umass.edu> krovetz@cs.umass.edu (Bob Krovetz) writes: >I have a file of s-expressions that are in upper and lower case. I would like to >read them, but keep the case intact (i.e., the s-expression would consist of atoms >of the form |Foo|). If the s-expressions will actually have the vertical bars as you suggest, then the case *will* be preserved. One of the effects of escaping a character in a symbol's printed representation is to prevent case conversion. If, however, you were using the vertical bars above as delimiters in your example and they don't actually appear in the file, there is no portable way to do it in current Common Lisp implementations. X3J13 has proposed the addition of the READTABLE-CASE attribute of readtables; see p.549 of CLtL2 for a description of it. In your case you would want to do something like: (let ((*readtable* (copy-readtable nil))) (setf (readtable-case *readtable*) :preserve) ;; read the file ) Some Common Lisp implementations already provide some way to get this behavior, but they will differ from implementation to implementation. -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar