Lisp HUG Maillist Archive

simple way to preserve case?

Is there an easy way to run LW in preserve-case (or lower-case) mode?

I'm building a compiler-compiler, or source-to-source transformer.

I want to read lower-case symbols and lists from a file, manipulate them, then 
write them out, preserving case. 

The "naive" approach results in upper-case output.  I can fix this by 
carefully using |'ed symbols and setting the reader's case, but, maybe there 
is something even simpler that will cause me less work (like an option to run 
LW in lower-case mode)?

thanx
pt


Re: simple way to preserve case?

Unable to parse email body. Email id is 2232

Re: simple way to preserve case?

* tarvydas  wrote:
> from a file appear to be written back in the original case, but the symbols 
> that I "generate" are always written out in upper case, e.g.  both of the 
> below examples write "DEFUN" out in upper case

> (pprint `(defun <stuff-read-from-file>))

> (pprint `(DEFUN <stuff-read-from-file>))

> Is that a symptom of the bug, or just a symptom of my continued 
> misunderstanding? :-)

The latter.  In the above, the source code is almost certainly read
with a standard readtable, so the DEFUN is translated to upper case in
the normal way.  When you print it, with the magic readtable in force,
the printer is doing its job and printing it in such a way that it can
be read.

The important thing to think about is what readtable is in effect
when.  Since you almost certainly want a standard (or at least a
translating-to-uppercase) readtable in effect when the system reads
your code (as opposed to your data), you'll need to make sure that any
symbols that you want to have lowercase names that you create at that
point are suitably escaped.  You could use a non-case-translating
readtable to read your code too, but then you'd have to WRITE IT LIKE
THIS...

--tim


Updated at: 2020-12-10 08:56 UTC