green's functions, passing functions to a routine



> Maxima is inconsistent about whether or not to evaluate the name
> of a function. If f is already the name of a function, then f is not
> evaluated in the expression f(t); but it is evaluated otherwise.
> I'm going to guess that you have a function named f somewhere
> in your program. An easy workaround is to name the formal argument
> something obscure like f% or whatever.

I have been looking for an at least quasi-robust solution that doesn't
involve choosing ugly function names. Using apply rather than
a function call seems to protect against premature evaluation...

fold(f,x,v) := block([res],
  res:apply(f,[x,v[1]]),
  for a in rest(v,1) do
  res:apply(f,[res,a]),res);

Then I can do this and it works.

(%i26) f(x) := x$
(%i27) fold(g,x,[a,b,c]);
(%o27) g(g(g(x,a),b),c)

If instead I call f like f(res,a) in fold, rather than using
apply, then I get :

(%i15) fold(g,x,[a,b]);
Too many arguments supplied to f(x):...

because it is trying to call f(x):=x

I have been trying various combinations of single and
double quotes, eg,
fold('f,x,v) := ...,
but I have not found another solution.