%mathpiper,def="PrintList"

//////////////////////////////////////////////////
/// Print a list using a padding string
//////////////////////////////////////////////////

10 # PrintList(list_IsList) <-- PrintList(list, ", ");
10 # PrintList({}, padding_IsString) <-- "";
20 # PrintList(list_IsList, padding_IsString) <-- PipeToString() [
	Local(i);
	ForEach(i, list) [
		If(Not(IsEqual(i, First(list))), WriteString(padding));
		If (IsString(i), WriteString(i), If(IsList(i), WriteString("{" : PrintList(i, padding) : "}"), Write(i)));
	];
];

%/mathpiper



%mathpiper_docs,name="PrintList",categories="User Functions;Lists (Operations)"
*CMD PrintList --- print list with padding
*STD
*CALL
	PrintList(list)
	PrintList(list, padding);

*PARMS

{list} -- a list to be printed

{padding} -- (optional) a string

*DESC

Prints {list} and inserts the {padding} string between each pair of items of the list. Items of the list which are strings are printed without quotes, unlike {Write()}. Items of the list which are themselves lists are printed inside braces {{}}. If padding is not specified, a standard one is used (comma, space).

*E.G.

In> PrintList({a,b,{c, d}}, " .. ")
Result: " a ..  b .. { c ..  d}";

*SEE Write, WriteString
%/mathpiper_docs