Subject: [clisp-list] getting compile-time values into code

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Thu Feb 20 09:05:03 2003

Hi,

I came up with the following, non-working piece of code:

I have a set of macros (not shown) whose macroexpansion adds to *columns-used*. The idea is that during evaluation or compilation, I gather information about which columns from a database are actually accessed.
(defvar *columns-used* '())

Then I want to store this value of *columns-used* into some place.

(defvar *analyse-funktionen* (make-hash-table :test #'eq))
(defmacro define-ananalyse (((var class)) &body body)
  (check-type var symbol)
  ;;TODO does not work in compiled mode: need *columns-used* from compiler environment
  (let ((lambda-form `(lambda (,var .line. .start-positions. .stop-positions.) ,@body)))
    `(eval-when (load compile eval)
      (let ((*precompile* nil)
	    (*columns-used* '()))
	(format *trace-output* "Columns for ~S so far: ~S~%" ',class *columns-used*)
        (setf (gethash ',class *analyse-funktionen*)
	      (list (function ,lambda-form) ',lambda-form *columns-used*))
	(format *trace-output* "Columns now: ~S~%" *columns-used*)
))))

When loading a file compiled with this, the effect is clear: the third element in the list will be NIL. The reason is, of course, that when reading the compiled file, no macroexpansion occurs, so *columns-used* is not modified at load-time.

In interpreted more everything is fine:
Columns for ZUGRIFFE so far: NIL
Columns now: (I/F_DIR PROTO SERVICE TIME DATE TYPE ACTION)

Using (load :compiling t)
Columns for ZUGRIFFE so far: NIL
Columns now: (I/F_DIR PROTO SERVICE TIME DATE TYPE ACTION)
Columns for ZUGRIFFE so far: NIL
Columns now: NIL
One of these comes from eval-when compile, the second from eval-when eval.

Any idea? Sounds familiar?
	Jörg Höhle.