From: Steve Gonedes
Subject: Re: changin readtable to read english text
Date: 
Message-ID: <6p9r72$mjl@bgtnsc03.worldnet.att.net>
·····@sip.medizin.uni-ulm.de (kp gores) writes:


< how do ic hange the read-table to read in english text with the read
< function? sentences like "Bob, who said (:-)))' " shoud be accepted.
<
< as far as i know, i can change the syntax of eg "," with
< set-syntax-from-char to be the same as #\a, that is a constituient and not
< a terminating macro.
< is that all i need to do???
<
< regards
<   kp

Setting the entire readtable up to direguard any lisp-like statements
would probably be a _real_ lot of work. What you could do instead is
setup a reader-macro so you can do

(def-english
  #!
   words ... ()
  !#
 "Some words").

Here is an example for reading perl scripts that I have, it will
probably work for english as well...Just gotta change the function
names. Also you'll have put the functions defining the readtable into
a seperate file from the functions that will be using the readtable.
I've tried to indicate this below.

Also this is a slight bit inefficient - but it seems to work and
should at least give you an idea of how you may be able to handle
these types of ugly situations (this will not strip out the comments,
because you need it for english).

;;; File eng.lisp

(defun english-reader (stream char prefix)
  (declare (ignore prefix char))
  (coerce
   (loop for i = (read-char stream nil nil t)
       until (or (null i)
                 (and (eql i #\#)
                      (eql (peek-char nil stream nil #\! t) #\!)
                      ;; gobble that last #\! char
                      (read-char stream nil nil)))
       collect i)
   'simple-string))

(defvar *english-readtable*
    (let ((readtable (copy-readtable nil)))
      (set-dispatch-macro-character #\#
          #\! #'english-reader readtable)
      readtable))

(defun format-english (words)
  words)

(defmacro def-english (name words &optional doc)
  "Define a constant named NAME with formatted words WORDS"
  `(defconstant ,name
       ,(format-english script)
     ,doc))

;;; eof eng.lisp

;;; File esamp.lisp

(eval-when (:compile-toplevel :load-toplevel :execute)
  ;; this is very important
  (setq *readtable* *english-readtable*))


(def-english +some-words+
  #! /usr/local/bin/perl

# April 21, 1998
# Tuesday 03:45:10 AM
#
# This will make multimaster instances from the text metric files

opendir (DIR, ".");
foreach $file (grep /\.txt/, readdir (DIR)) {
   open(FILE, "$file");
   while (<FILE>) {
      next unless /^PC /;
      $file =~ s/\.txt//;
      $_ =~ s/^PC (\d+) (\d+) ; PL \( ([A-Z][A-Z]) \) \( ([A-Z][A-Z])\).*/$1_$3_$2_$4/;
      if (-f "$file.pss") {
         die "$file.pss exists!\n";
      } else {
         print STDOUT "$file\_$1\_$3\_$2\_$4\n";
      }
      open (PSS, ">$file\_$1\_$3\_$2\_$4.pss");
     ... gross ...
  #!
  "Some words")

USER(1): :ld eng
; Loading /home/steve/lib/Scripts/LISP/eng.lisp
USER(2): :ld esamp
; Loading /home/steve/lib/Scripts/LISP/esamp.lisp
USER(3): +some-words+
" [ ~45 lines deleted ] "

No need to manually add any backslashes or anything like that. You
should probably compile this to prevent death by consing. Hope this
helps...