[Maxima] Variables in function definition problem

praimon praimon at gmail.com
Tue Jun 26 10:04:54 CDT 2007

```Hello,
It seems to me that the variables I use on the left-hand side of a
function definition should be irrelevant. And so it is here:

(%i4) myfunc(f,list):=g(f,list)\$
(%i5) myfunc(h,[a,f]);
(%o5) 				 g(h, [a, f])

The result is correct even though the 'f' fed to the new function was
used in its original definition.

However, here's function I created that takes an arbitrary function
and list of lists and does an outermap operation on them:

(%i6) myouter(f,lists):=apply(outermap,cons(f,lists))\$
(%i7) myouter(h,[[c,d],[e,f]]);
(%o7) 		   [[h(c, e), h(c, h)], [h(d, e), h(d, h)]]

This result is wrong. The function seems to 'remember' that I used 'f'
in the original definition and is getting confused. If I explicity
declare 'f' as a local variable it works as expected:

(%i8) myouter(f,lists):=block([f],apply(outermap,cons(f,lists)))\$
(%i9) myouter(h,[[c,d],[e,f]]);
(%o9) 		   [[f(c, e), f(c, f)], [f(d, e), f(d, f)]]

...but I would never have thought that I needed to do that. And I
haven't been doing it in the course of my functions definitions, so
now I wonder how many of those functions are in similar danger. Am I
misunderstanding something or is there some idiosyncrasy in the
definition I used?
```