[Maxima] compilation of macro printf
robert.dodier at gmail.com
Sat Nov 24 11:24:55 CST 2007
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)$
> (%i4) compile(foo)$
> (%i5) foo(7)$
> 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);
=> #<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.
More information about the Maxima