From: Joerg-Cyril Hoehle
Subject: eval-when situation question
Date: 
Message-ID: <1992Dec15.190606.102345@eratu.rz.uni-konstanz.de>
Hi,

I've got a file that makes use of a modified *readtable* provided by
an other file, and I'd like the environment (say *readtable*) not
altered by the loading (or even compilation) of that file.

This read-table modifies (using set-macro-character) the entry for ?.
The example file looks like this:

(eval-when (compile)
	(setq *readtable* *special-readtable*))

(defvar foobar '((?a) ?b))

Ideally, the reader would expand the ? at read-time, so that the
compiler wouldn't even see the ?. I believe that the (eval-when
(compile) #) takes care of this.

If there's no compiler or if loading the .lisp file, I expect the
*readtable* to be set during the loading process, whatever that means,
and foobar to get the correct, expanded, value.

But I'm wondering why CLtLII, p.89 provides a similar example with
set-macro-character and says to use (eval-when (compile load eval) #),
not only (compile) as the set of situations.

Thanks for shedding light on this issue,
 	Joerg.
······@inf-wiss.ivp.uni-konstanz.d
From: Bruno Haible
Subject: Re: eval-when situation question
Date: 
Message-ID: <1gnlgbINN6bs@nz12.rz.uni-karlsruhe.de>
Hi,

Joerg asks:
> I've got a file that makes use of a modified *readtable* provided by
> an other file, and I'd like the environment (say *readtable*) not
> altered by the loading (or even compilation) of that file.

Use

   (eval-when (compile eval)
     (shiftf *original-readtable* *readtable* *special-readtable*)
   )

at the beginning and

   (eval-when (compile eval)
     (setq *readtable* *original-readtable*)
   )

at the end of that file.

> Ideally, the reader would expand the ? at read-time, so that the compiler
> wouldn't even see the ?. I believe that the (eval-when (compile) #)
> takes care of this.

Exactly that is happening.

The "eval" situation accounts for the case where the uncompiled .lisp file
is loaded. The "load" situation is not needed here since it denotes loading
of the compiled .fasl file which of course does not contain the ? any more.

> But I'm wondering why CLtLII, p.89 provides a similar example with
> set-macro-character and says to use (eval-when (compile load eval) #),
> not only (compile) as the set of situations.

Because it is usual to modify the environment, for example to test the
read macro.

      Bruno
      ······@ma2s2.mathematik.uni-karlsruhe.de