[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Processing TEXT in MCL



At 11:52 AM 7/31/94 -0700, David Evan Jones wrote:
 >I'm using MCL to extract relevant information from text files.  I have
 >three major problems doing this.  Solutions to ANY of these would be
 >VERY helpful:
 >
 >1.  How do I tell MCL to open AS TEXT a file that is not type 
 >'TEXT'???

It depends whether you're opening a new window to view and edit
interactively, or calling a lisp program which opens the window
to read it under program control. From your other questions (below)
I'll bet you want the latter.

The OPEN command in the menu limits your choices to TEXT files, but
actually Fred can open and read the data fork of any file if you want.
There's two ways to do this:
  1) Call (ed (choose-file-dialog)). 
  2) Change your file to type TEXT using ResEdit or a shareware app
     - which I use all the time for this - called FileTyper, or use
     (set-mac-file-type (choose-file-dialog) :|TEXT|)
     Then you can go ahead and use the Open command in the File menu.

To open your file under program control, it doesn't matter what the 
creator type is. Just use something like this:

   (with-open-file (stream the-filename :direction :input)
        ...)

 >2.  How to automatically eliminate commas?

Sounds like you need to write a "reader", which is a function that 
opens and reads your file for you. There's a whole lot of ways to
do this, but a cheapo way might be to loop inside the 
with-open-file body (above), alternating calls to READ (to read 
a value) and READ-CHAR (to read and ignore the comma after each
value).

 >3.  As far as I can tell, MCL is completely case-insensitive.  Is 
 >there any way around this??? Is there a way for MCL to
 >distinguish between upper and lower case in this text-file???

You need to set the readtable-case of the readtable to :PRESERVE,
or else read the input as strings, not symbols. Check out page 549
in Common Lisp the Language, 2nd edition.

Notice the code example on that page calls copy-readtable and uses
a copy within a let. You should do that too - you really want to avoid
messing with the top-level readtable that MCL uses. By making a copy,
it'll be in effect strictly while you're reading in your data files.
(see also around p 562)

More ambitious hackers can read that whole section and get into hacking
the entire reader mechanism.