[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*)))
(PRINT-STATISTICS *SOLUTION-FAILURES* *GOAL-FAILURES* *SELECTIVE-GOAL-FAILURES* *UNIFICATION-FAILURES*)
(CASE MODE
(:ONE
(THROW :SUCCEED
:SUCCEED))
(:ALL)
(:QUERY
(COND ((Y-OR-N-P "Do you want another solution? "))
(T (THROW :SUCCEED
:SUCCEED)))))))
QUERY is a macro defined as:
(defmacro QUERY (name query (&key (statistics? t)
(selective-backtracking? t)
(failure))
&body success)
(compile-query name (symbol-value name) query success failure statistics?
selective-backtracking?))
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:
LT::MAPFORMS-DECLARE
COMPILER:OPTIMIZE-FORM
SI:PARSE-BODY-DECLARATIONS
LT::COPYFORMS-1
LT::MAPFORMS-DECLARE
LT::COPYFORMS-1
SI:PARSE-BODY-DECLARATIONS
COMPILER:OPTIMIZE-FORM
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.
Jeff
-------