%mathpiper,def="MapArgs"

TemplateFunction("MapArgs",{expr,oper})
[
  Bind(expr,FunctionToList(expr));
   ListToFunction(Concat({expr[1]},
     Apply("MapSingle",{oper,Rest(expr)})
   ) );
];
UnFence("MapArgs",2);
HoldArgument("MapArgs",oper);

%/mathpiper



%mathpiper_docs,name="MapArgs",categories="User Functions;Control Flow"
*CMD MapArgs --- apply a function to all top-level arguments
*STD
*CALL
	MapArgs(expr, fn)

*PARMS

{expr} -- an expression to work on

{fn} -- an operation to perform on each argument

*DESC

Every top-level argument in "expr" is substituted by the result of
applying "fn" to this argument. Here "fn" can be either the name
of a function or a pure function (see Apply for more information on 
pure functions).

*E.G.

In> MapArgs(f(x,y,z),"Sin");
Result: f(Sin(x),Sin(y),Sin(z));
In> MapArgs({3,4,5,6}, {{x},x^2});
Result: {9,16,25,36};

*SEE MapSingle, Map, Apply
%/mathpiper_docs