So I define a macro (defmacro macro-print (str) (print "hi") and then run
(let ((i 0))
(while (< i 3)
(macro-print i)
(setq i (+ 1 i)))
according to the Elisp manual, the interpreter should evaluate (macro-print i) three times, and hence I should see "hi" printed three times, yet, I only see it once. This makes me think that the form is somehow being compiled and the macro expanded during compilation. This seems to be the same thing that happens in SBCL. Running the same experiment there, I see one "hi" when the evaluator mode is set to compile, and three "hi"s when it is set to interpret. As I understand the Hyperspec, the interpret result is the correct behavior when evaluating Common Lisp (the compile behavior I am not sure, I have not read that part of the Hyperspec yet).
Elisp does not have a hyperspec, but the manual suggests that I should be seeing interpret-like behavior, why then do I see compile-type behavior? Shouldn't the same piece of code behave the same way regardless of compilation/interpretation?
EDIT To address Drew's feedback:
For 1,2) I read the Elisp manual and according to the evaluation rules of 'while', every time the condition form evaluates to true, we evaluate the body forms. In my example, one of the body forms is a macro, which according to the macro evaluation rules, must be expanded whenever evaluated. This means the macro should be expanded 3 times in the loop (each time printing "hi"), but when run, I only see "hi" once. Why is the macro being expanded just once? Is it that when we expand it, we replace it in the 'while' form? The connection I see to Common Lisp is that this is the CL behavior for "compile" mode where we expand all macros first as detailed in the Hyperspec, and then evaluate the form. Does such an interpreted vs. compiled distinction exist in Elisp?
For 3), I know this isn't the right way to use macros, but it is the easiest example I could find that illustrates my confusion with the Elisp evaluation model.
C-h eto see it)?(print "hi")in it?print. Is there some setting I am missing?