From: John Atwood
Subject: why is my *readtable* trashed?
Date: 
Message-ID: <7q40dp$2fg$1@news.NERO.NET>
I'm trying to use the pretty printer, and altering the *readtable* to
preserver case.  But I'm unable to restore the *readtable* (though I am
able to restore it to the standard). After I define and run the defun
below, I can no longer type in any commands in lower case (upper still
works). Can someone tell me what's going on?

I'm also trying to find out how to read/write comments and how to
use the pretty-printer in general, but i'll start another thread for
that.


Thanks,

John Atwood


(defun pp2 (fileName)
 (let ((hold-readtable (copy-readtable))
       (hold-print-pretty *print-pretty*)  )
   (setf *print-pretty* T)
   (setf (readtable-case *readtable*) :preserve)
 
   (with-open-file (stream fileName)
     (do ((lispObject (read stream) (read stream nil 'eof)))
         ((eq lispObject 'eof) )
         (pprint lispObject)))
 
   (copy-readtable hold-readtable *readtable*)
  ;(setq *readtable* (copy-readtable nil)) ;restore to standard
   (setf *print-pretty* hold-print-pretty)  ))

From: Kent M Pitman
Subject: Re: why is my *readtable* trashed?
Date: 
Message-ID: <sfw6722bdct.fsf@world.std.com>
·······@bronze.CS.ORST.EDU (John Atwood) writes:

> 
> I'm trying to use the pretty printer, and altering the *readtable* to
> preserver case.  But I'm unable to restore the *readtable* (though I am
> able to restore it to the standard). After I define and run the defun
> below, I can no longer type in any commands in lower case (upper still
> works). Can someone tell me what's going on?

First, you should copy the readtable and modify a copy.  Don't modify
the original.  Doing that alone would probably fix your problem.
That is, you should just instantiate the copy, use it, and then discard it.

Second, you have no UNWIND-PROTECT in there to set the value back to the
old value, so if there is an error, your unsetup is lost.

Third, I don't have time to look at this in detail, I *think* you
might have a bug in your understanding of what COPY-READTABLE does
with two args.  You should double-check the HyperSpec for a
description of what it actually does to make sure you're not confused.
But if you fix it in the way I've suggested in the first suggestion
above, this will be moot.

> I'm also trying to find out how to read/write comments and how to
> use the pretty-printer in general, but i'll start another thread for
> that.

You'll have to write your own reader to read/write comments.   You almost
surely don't want to do that.  I really think this is the wrong technology
for what you want to do.  Learn how to program Emacs-Lisp and just use its
identing capabilities as part of a batch script.  (Emacs-Lisp can be invoked
from the command line, and so can be called from a CL as a subroutine if
you need to by calling out to the system.)  But, also, if you have code you
need to see pretty printed, the simplest solution is to make sure it is always
pretty printed to begin with.  If it has comments, it was probably created
by a human, and there's no good reason for it to not be pretty printed.

Mostly I really suspect there are better things you could be doing with your
precious days on earth than writing this particular program.
From: Barry Margolin
Subject: Re: why is my *readtable* trashed?
Date: 
Message-ID: <U7ix3.456$m84.7749@burlma1-snr2>
In article <···············@world.std.com>,
Kent M Pitman  <······@world.std.com> wrote:
>Third, I don't have time to look at this in detail, I *think* you
>might have a bug in your understanding of what COPY-READTABLE does
>with two args.  You should double-check the HyperSpec for a
>description of what it actually does to make sure you're not confused.

While I agree with your recommendation to use a temporary readtable rather
than modifying the standard one, it looks to me like his understanding of
COPY-READTABLE is correct.  The HS says that if to-readtable is not NIL,
it's modified in place and returned.

I suspect his implementation has a bug that it doesn't copy the case
attribute when performing the two-argument COPY-READTABLE.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.