problem with recursive functions



On 10/6/06, Norber Vegh <jack at omega.telia.net> wrote:
>
> f[1] : lambda( [x], makelist( i, i, 1, x ) );
> f[d] := lambda( [x], 2*f[d-1](x) );


Maxima does not support lexical scoping, so f[2] in your example evaluates
to lambda([x],2*f[d-1](x)) (with a free 'd').

To simulate lexical scoping, you can use something like this:

f[1]: lambda([x],makelist(i,i,1,x))$
f[d]:subst(d,'d,'( lambda([x],2*f[d-1](x)) ))$

but I am not sure this is the clearest way to solve your problem.

Why do you want to do this with f[d](x) rather than f(d,x)?  In Maxima,
f[d]:=... has a specific usage, memoizing, which frankly makes the semantics
rather messy, though it is very useful when not memoizing would be
intolerably inefficient.

         -s