%mathpiper,def="UnFlatten"

10 # UnFlatten({},_op,_identity) <-- identity;
20 # UnFlatten(list_IsList,_op,_identity) <--
     Apply(op,{First(list),UnFlatten(Rest(list),op,identity)});

%/mathpiper



%mathpiper_docs,name="UnFlatten",categories="User Functions;Lists (Operations)"
*CMD UnFlatten --- inverse operation of Flatten
*STD
*CALL
	UnFlatten(list,operator,identity)

*PARMS

{list} -- list of objects the operator is to work on

{operator} -- infix operator

{identity} -- identity of the operator

*DESC

UnFlatten is the inverse operation of Flatten. Given
a list, it can be turned into an expression representing
for instance the addition of these elements by calling
UnFlatten with "+" as argument to operator, and 0 as
argument to identity (0 is the identity for addition, since
a+0=a). For multiplication the identity element would be 1.

*E.G.

In> UnFlatten({a,b,c},"+",0)
Result: a+b+c;
In> UnFlatten({a,b,c},"*",1)
Result: a*b*c;

*SEE Flatten
%/mathpiper_docs