lambda for mat_function



Hi, 
I think this is a bug. The problem is not the lambda expression. 
I try to point to the problem: 

(%i1) display2d:false$

(%i2) foo(f,x):= block([i:2], f(x))$

mat_function is written like foo. 
For internal loopings etc. it uses the variables i,ii,j,k,n and some more. 
My i in foo stands for one of these and interferes with an i which is passed in by the function f:

(%i3) bar(x):= x^i$

(%i4) foo(bar,x);

(%o4) x^2

In your example you protect the exponent i by using block([i], .

(%i5) baz(x):= block([i],x^i)$

(%i6) foo(baz,x);

(%o6) x^i

You also can do this with a lambda expression:

(%i7) foo(lambda([x],x^i),x);

(%o7) x^2

(%i8) foo(lambda([x],block([i],x^i)),x);

(%o8) x^i

I hope the last solves your problem.

I think that diag.mac should be revised. 
I found some presumably unintended programming constructs.
To avoid variables beeing catched gensym-like names could be used 
or the functions could be rewritten in Lisp using defmspec: E.g.

(%i9) :lisp (defmspec $foo1 (a) (let ((i 2)(f (cadr a)) (z (caddr a))) (mfuncall f z)))

(LAMBDA-CLOSURE () () () (A)

  (LET ((I 2) (F (CADR A)) (Z (CADDR A))) (MFUNCALL F Z)))

(%i9) foo1(bar,x);

(%o9) x^i

(%i10) foo1(lambda([x],x^i),x);

(%o10) x^i

Greetings
Volker van Nek



Xiang Liu schrieb:
>  *Function:* *mat_function** (f,mat)*
>
> Returns *f(mat)*, where f is an analytic function and mat a matrix.
> I have tried:
>
> load(diag);
>
>
> A:matrix([4,1,2],[0,2,-4],[0,1,6]);
>
>
> mat_function(lambda([x],x^k),A);
>
>
> fpow(x):=block([k],declare(k,integer),x^k);
>
>
> mat_function(fpow,A);
>
>
> The question is: why lambda expression doesn't work here?[?]
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>