## list-to-string.pkg
# Compiled by:
#
src/lib/std/standard.lib### "I wish to work miracles."
###
### -- Leonardo da Vinci
package list_to_string
: (weak) List_To_String # List_To_String is from
src/lib/src/list-to-string.api{
# Given an initial string (init), a separator (sep), a terminating
# string (final), and an item formatting function (fmt), return a list
# formatting function. The list ``[a, b, ..., c]'' gets formatted as
# ``init + (fmt a) + sep + (fmt b) + sep + ... + sep + (fmt c) + final.''
#
fun list_to_string' { first, between, last, to_string }
=
format
where
fun format [] => first + last;
format [x] => cat [first, to_string x, last];
format (x ! r)
=>
f (r, [to_string x, first])
where
fun f ([], l) => cat (reverse (last ! l));
f (x ! r, l) => f (r, (to_string x) ! between ! l);
end;
end;
end;
end;
fun list_to_string f
=
list_to_string'
{ first => "[",
between => ", ",
last => "]",
to_string => f
};
}; # package list_to_string