Steve,
Thanks for the info. Comments/questions inline below.
-s
On Thu, Nov 19, 2009 at 11:45 AM, Steve Haflich <smh at franz.com> wrote:
> Stavros Macrakis <macrakis at alum.mit.edu> wrote:
>
> ? OK, define-compiler-macro was new to me -- I guess it is never used at
> ? runtime. ?Is that really true? ?Does it mean that you can't debug
> ? define-compiler-macro macros when running interpretively? ?That seems
> ? problematic.
>
> A single symbol name can carry both a compiler macro definition and a
> regular function or macro. ?The usual sane practice is to define a the
> compiler macro to have the same behavior as the function or macro,
> although this is not required.
Presumably the idea is to have the same *black-box* behavior. In the
current version of mopers/opers.lisp, it appears that the macro
definition has been *mechanically* converted to a regular function for
runtime use, which seems peculiar. For example, we have
(defun add (&rest terms)
(if (= (length terms) 2)
(apply #'add2 terms)
(apply #'addn `(,terms t))))
(define-compiler-macro add (&rest terms)
(if (= (length terms) 2)
`(add2 , at terms)
`(addn (list , at terms) t)))
instead of what I'd have written by hand:
(defun add (&rest terms)
(if (= (length terms) 2)
(add2 (car terms) (cadr terms))
(addn terms t)))
> There is not requirement in the ANS that the implementation's compiler
> expand and use a compiler macro, although generally they do.
What is the ANS?
> You'll
> need to check each implementation to see if there are dependencies on
> the several optimize declaration qualities. ?(A compiler macro may _not_
> be expanded by the compiler is the function or macro is locally declared
> notinline.) ?You cannot otherwise ever depend on a compiled macro not
> being used, since implementations are permitted to accomplish
> `interpreted' execution, aka eval, as:
>
> ?(defun eval (form) (funcall (compile nil `(lambda () ,form))))
So presumably you should not write code like
(define-compiler-macro f (x) (f x)) ; punt to function
because this could result in an infinite recursion (any more than you
could in the old macro system).
I wonder if there is a way to *force* the interpreted execution in
order to debug the macro?
> Compiler macros can be are extremely important for runtime efficiency,
> allowing small code snippets to be inlined, while allowing the
> first-class function to exist, for instance, so it can be passed as a
> :key or :test function argument to one of the sequence functions.
Understood completely! Just trying to understand the detailed
semantics in current Lisps -- I wrote the original mopers code using
defmacro 35 years ago!
-s