[m-dev.] some string manipulation funcs

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Dec 20 22:45:08 AEDT 1999


On 05-Nov-1999, David Glen JEFFERY <dgj at fengshui.cs.mu.OZ.AU> wrote:
> 
> Philip Dart forwarded these to me. Any complaints if I add them to the string
> module?

These look OK to me.

My main complaint would be that really we ought to solve
this by providing a type class for output streams;
then we'd need only one predicate, rather than needing
separate predicates io__write_list and string__list_to_string.

But probably that should wait for version 2 of the standard library;
it would be OK to add these in the mean time.

> :- func string_list_to_string(func(X) = string, string, string, string,
> 		list(X)) = string.
> :- mode string_list_to_string(func(in) = out is det, in, in, in,
> 		in) = out is det.
> %	string_list_to_string(F, Pre, In, Post, List).
> %		Converts a list to a string using the function F to convert
> %		each element to a string, separating each element by In,
> %		and pre- and post-fixing the rsult with Pre and Post.  Eg.
> %		F = (func(I) = O :- string__int_to_string),
> %		string_list_to_string(F, "<", "; ", ">", [1,2,3]) = "<1; 2; 3>"

The example in the comment is wrong; `I' and `O' are singleton variables.
Also we have a function version of string__int_to_string in the standard
library now.  Probably it should just be

	%	string__list_to_string(string__int_to_string,
	%		"<", "; ", ">", [1,2,3]) = "<1; 2; 3>"

> :- func string_list_to_string(func(X) = string, list(X)) = string.
> :- mode string_list_to_string(func(in) = out is det, in) = out is det.
> %	string_list_to_string(F, List).
> %		Converts a list to a string equivalent to
> %		string_list_to_string(F, "[", ", ", "]", List). Eg.
> %		F = (func(I) = O :- string__int_to_string),
> %		string_list_to_string(F, [1,2,3]) = "[1, 2, 3]"

Likewise here.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list