scope of function-parameters



Hello,

I would appreciate very much if anybody could give me (a hint to) information about the difference of the "square brackets" ([ ]) in a block and the "local"-statement. I don't find the manual very clear in this point.

The problem:

I wanted to use a function as a parameter -- every calculus student knows want is meant by

/*   */
dqf(f, a, h):= (f(a+h) - f(a))/h;
/*   */

This definition, which works fine t.ex. with Maple (of course with a different syntax), doesn't work with Maxima: if f is already (globally) defined at the moment of the definition of dqf (that means if f is bound) then this global f is used!

I made a simpler example (but with some local variable to keep things general enough) -- and after many tries I succeded: but, to be serious, I don't know why:

/*   */
kill(all);
f(x):= sin(x);
ff(x):= cos(x); /* try even WITHOUT this statement to see that we need ff in [ ] too! */
testF(f, x):= block([ff, a: 3],
  local(ff),
  ff: f,
  a*ff(x));
g(x):= x^2;
testF(g, 2);
f(2);
ff(2);
/*   */

Can this be done simpler? What is the idea of "dynamical binding" (with respect to function-parameters) in Maxima?

=====

By the way, the problems are similar if you will construct a function as return of a function. The example given in the "Maxima Beginner?s FAQ" (http://cadadr.org/maxima/faq.html) is obviously wrong if x is bound:

/*   */
kill(all);
x: 7;
make_fn(n) := funmake('lambda, [[x], n+x]);
make_fn(3)(w);
/* ==> error */
/*   */

=====


Thank you very much for help resp. clarification
Ulrich

-- 
GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 f?r nur 19,99 ?/mtl.!*
http://portal.gmx.net/de/go/dsl