compilation of macro printf



On 11/24/07, van Nek <van.nek at arcor.de> wrote:

> (%i1) foo(n) := printf(true,"~d",n)$
> (%i2) compile(foo)$
> ...
> (%i3) foo(7)$
> 7
> (%i4) compile(foo)$
> ...
> (%i5) foo(7)$
> n
>
> printf is a macro function from package stringproc.
>
> Is this behaviour due to printf itself or is there a general problem
> with compiling macro functions?

The translator generates the following code, which seems OK,
for a printf call:

foo(x) := printf (true, "FOO: ~a~%", x);
translate (foo);
:lisp #'$foo
 => #<FUNCTION $FOO ($X) (DECLARE (IN-DEFUN $FOO) (SPECIAL $X)) (BLOCK
$FOO ($PRINTF T FOO: ~a~% $X))>

But printf expands its argument x to 'x so it isn't evaluated:

:lisp (macroexpand '($printf t "FOO: ~a~%" $x))
 => (FORMAT T FOO: ~a~% 'x)

I think that's the cause of the observed behavior.
I don't know if printf should sometimes quote and sometimes not,
or always not quote, or what.

best

Robert