[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Why does my Macro get expanded 8 times?
I have the following function, which is automatically generated
from a Prolog query (my own Prolog compiler).
(DEFUN TOP-LEVEL (MODE)
(QUERY SIMPLE-EXAMPLE ((P C)) (:STATISTICS? T :SELECTIVE-BACKTRACKING? T :FAILURE
(PRINT-STATISTICS *SOLUTION-FAILURES* *GOAL-FAILURES* *SELECTIVE-GOAL-FAILURES* *UNIFICATION-FAILURES*)
(COND ((Y-OR-N-P "Do you want another solution? "))
(T (THROW :SUCCEED
QUERY is a macro defined as:
(defmacro QUERY (name query (&key (statistics? t)
(compile-query name (symbol-value name) query success failure statistics?
Where COMPILE-QUERY is a function which actually produces a hairy amount
of Lisp code. If the variable CODE is set to the list (DEFUN TOP-LEVEL (MODE) ...)
and I do a (compile (eval CODE)), my function COMPILE-QUERY actually gets called
*eight* times from the following routines:
This is real bad because COMPILE-QUERY might take a long time to run. It also
might generate different code each time (like different GENSYM'ed variables).
In my case it doesn't, but I might like to in the future. What is particularly
annoying is that if it prints out warning messages then I get *eight* copies
of each message. This is a bug which should be fixed.