Hello Volker,
> nsum(n,s):=
> if n=0 then s
> else nsum(n-1,s+n)$
The translator output has some macros in it --
:lisp (symbol-function '$nsum)
shows the function definition after the macros are expanded.
For nsum as defined above I get
#<FUNCTION $NSUM ($N $S) (DECLARE (IN-DEFUN $NSUM) (SPECIAL $S $N))
(BLOCK $NSUM
(COND ((LIKE $N 0) $S) (T (SIMPLIFY (MFUNCTION-CALL $NSUM (ADD* $N
-1) (ADD* $S $N))))))>
I know of a couple of things to make this more concise --
(1) Tell the translator that $NSUM is a Lisp function.
(Sure, it should know that, but it doesn't.)
/* Next setq is a workaround -- undefined variable */
:lisp (setq *DECLARED-TRANSLATED-FUNCTIONS* nil)
declare_translated (nsum);
(2) Tell the translator n and s are integers.
nsum(n, s) := (mode_declare([n, s], integer),
if n = 0 then s else nsum(n - 1, s + n));
With those 2 changes I get this:
#<FUNCTION $NSUM ($N $S) (DECLARE (IN-DEFUN $NSUM) (SPECIAL $S $N)
(FIXNUM $S $N))
(BLOCK $NSUM (PROGN NIL (COND ((EQL $N 0) $S) (T (SIMPLIFY ($NSUM
(F+ $N -1) (F+ $S $N)))))))>
The (DECLARE (SPECIAL ...)) and (SIMPLIFY ...)
are there to ensure that translated code acts like interpreted code
(dynamic scope of variables, & simplification of every
function return value, respectively).
The documentation for function translation is under the
heading "Definitions for Function Definition"
(http://maxima.sourceforge.net/docs/manual/en/maxima_41.html#SEC161
at the moment). The documentation is hard to follow but
we can fix that.
hth
Robert