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

How to force the compiler to bind the *readtable* nicely?

Could anyone help me with the following problem:

I am writing a written French generator. This involves the manipulation of
complex syntactic structures. In order to make the description of these
structures easier to write and read (I dislike write-only code <Sussman
@ 88 ACM Lisp conf.>) I defined a set of read-macros. These macros let
me write syntactic structures in terms of their resulting description
instead of using long lisp forms which build them. To some extend
this is the same kind of idea as backquote.

Reading such structures (i.e. as program data) from files is trivial
(just rebind *readtable* with my own read table).

I also need to write such structures in some places of my program.

The whole point is that I want this readtable binding to remain local to
the places where my readtable is needed in order to keep things clean.
(i.e. I do not want to change the global readtable permanently
as this might interfere with other parts of the system
which is used in conjunction with my program.)

My problem is: how do I make the compiler process SOME of my files
with my readtable?

My first idea was: put something in my DEFSYSTEM which will inform the
compiler to do the rebinding (in the same way as it is possible to indicate
that some module is to be processed in some package, i.e. with the *package*
variable rebound adequately).  Unless I missed something no such feature
seems to be documented.

The second idea was to wrap the code using the readtable in a COMPILER-LET:

(compiler-let ((*reatable* <code to build my readtable>))
   <code using the special readtable>)

I think this could not work as the WHOLE COMPILER-LET form (including
the <code using the special readtable>) is read before being evaluated
or compiled. Therefore the readtable is rebound "too late".

The third idea is in the following flavor:

(eval-when (compile eval)
   (setf old-readtable *readtable*
         *readtable* <code to build my readtable>))

<code using the special readtable>

(eval-when (compile eval)
   (setf *readtable* old-readtable))

This is not a nice way to do things
 - First I consider this code as ugly (This is a personal point of view)
 - Second, If anything goes wrong during the compilation (or evaluation)
   of <code using the special readtable> the global readtable remains
   modified. (Using unwind-protect won't help: it has the same drawbacks
   as compiler-let i.e. code being read before readtable binding).

Could anyone comment on this?

P.S.: I remember seeing code written in Zetalisp for a LMI Lambda
      in which files has a readtable file attribute.
      Obviously, this seems to be a solution to my problem!  But
      this attribute is not supported on the Symbolics implementation.

P.P.S: The system is implemented in Common Lisp and runs on
       Genera 7.1. (We're moving to 7.2 within a few days)

Pierre-Joseph GAILLY
Research Assistant,
Computer Science Departement,
Institut Montefiore, Bat B28,
University of Liege
B4000 Liege, Belgium
Email: U502801 @ BLIULG11.BITNET