scott@wiley.uucp (Scott Simpson) (08/03/90)
Can anyone explain to me how a Lisp compiler evaluates and processes forms? I have been reading the section of CLtL2 on eval-when and it is about as clear as mud. I also tried reading the beginning of Chapter 25 and it was no help either. If there are any documentation you could point me to I would appreciate it. Some questions I have are: - Is a separate environment created during compilation? - If so, why does a global variable get set when I compile a file containing (eval-when (compile) (setf *new* 1)) (using Sun CL 2.1.3)? In this case, the variable *new* is set to 1 after I type '(compile-file "temp.lisp")'. If I change "compile" to "load" it does it at binary load time and if I change "compile" to "eval" it only does it when I read in a regular lisp file. If a separate environment is created, why isn't the variable set within the compilation environment and then destroyed when the compilation is done and the compilation environment disappears? - Steele implies a separate environment is created when he says "'compile' specifies that the compiler should evaluate the body at compile time in the compilation context." I assume by compilation context he means compilation environment. If so, why didn't my above tests work? - What are not-compile-time mode and compile-time-too mode? The word "too" implies that compile-time-too mode is a strict superset of not-compile-time mode. Is this true? How so? My interpretation is that when lisp forms are simply read in, they are converted to S-expressions and evaluated. When compilation occurs, they are converted to S-expressions but they are not evaluated. Instead, the S-expression is converted to (almost) native code. The code is then evaluated when it is read in. If my assumption is correct, then compile-time-too mode wouldn't be a strict superset since it is doing something different and Steele's wording is confusing. I also looked at Steele's example: (eval-when (compile load eval) (set-macro-character #\$ #'(lambda (stream char) (declare (ignore char)) (list 'dollar (read stream))))) According to me empirical evidence with setf above, it appears to me that this would set $ to be a macro character in your interactive lisp environment after you compiled a file containing this. Steele implies otherwise. What gives? Scott Simpson TRW scott@coyote.trw.com