[m-rev.] for review: move string builder stream to standard library

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Apr 19 17:50:22 AEST 2007


On Thu, 19 Apr 2007, Ian MacLarty wrote:

> For review by anyone.
>
> Estimated hours taken: 0.5
> Branches: main.
>
> Move the string builder stream from extras to the standard library.
>
> library/string.builder.m:
> 	Move stream_util.string_builder to string.builder.
>
> 	Use builtin.copy instead of unsafe_promise_unique in the implementation
> 	of put/4 for the string builder stream.
>
> library/string.m:
> 	Include string.builder.

You also need to update the predicate mercury_std_library_module/1
in library/library.m.

> tests/hard_coded/Mmakefile:
> tests/hard_coded/string_builder_test.exp:
> tests/hard_coded/string_builder_test.m:
> 	Add a test case.
>
> extras/Mmakefile:
> extras/README:
> extras/stream/Mmakefile:
> extras/stream/README:
> extras/stream/impure.m:
> extras/stream/lowlevel.m:
> extras/stream/stream_old.m:
> extras/stream/stream_util.m:
> extras/stream/stream_util.string_builder.m:
> extras/stream/tests/Makefile:
> extras/stream/tests/stream_util_test.exp:
> extras/stream/tests/stream_util_test.m:
> 	Completely remove the streams modules from extras.  These modules
> 	are all deprecated now.

(For the record, Ian and I discussed this and decided that it was simpler
to just delete the stream package from extras, rather than expend the
any effort maintaining it; the stream support in the stdlib offers
significantly more functionality than this ever did.)

> Index: library/string.builder.m
> ===================================================================
> RCS file: library/string.builder.m
> diff -N library/string.builder.m
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ library/string.builder.m	19 Apr 2007 05:14:15 -0000
> @@ -0,0 +1,92 @@
> +%-----------------------------------------------------------------------------%
> +% vim: ft=mercury ts=4 sw=4 et
> +%-----------------------------------------------------------------------------%
> +% Copyright (C) 2006 The University of Melbourne.
> +% This file may only be copied under the terms of the GNU Library General
> +% Public License - see the file COPYING.LIB in the Mercury distribution.
> +%-----------------------------------------------------------------------------%
> +%
> +% File: string.builder.m.
> +% Main author: maclarty.
> +%
> +% This module implements a string builder stream.  It can be used to
> +% build up a string using string or character writers.
> +%
> +%-----------------------------------------------------------------------------%
> +%-----------------------------------------------------------------------------%
> +
> +:- module string.builder.
> +:- interface.
> +
> +:- import_module char.
> +:- import_module stream.
> +
> +%-----------------------------------------------------------------------------%
> +
> +:- type string_builder_stream.

I suggest calling that string_builder_handle.  The "stream" is really
the combination of both that and the state.

> +:- type string_builder_state.
> +
> +:- pred init(string_builder_stream::out, string_builder_state::uo) is det.

It may be worth having a TODO list somewhere in the implementation
section that mentions that if the restriction on repeated variables
in typeclass instances is lifted then this should actually be:

 	:- type string_builder_stream(T).
 	:- type string_builder_state(T).

 	:- some	[T] pred init(string_build_stream(T)::out,
 		string_builder_state(T)::uo) is det.

> +:- instance stream.stream(string_builder_stream, string_builder_state).
> +
> +:- instance stream.output(string_builder_stream, string_builder_state).
> +
> +:- instance stream.writer(string_builder_stream, string, string_builder_state).
> +:- instance stream.writer(string_builder_stream, char, string_builder_state).
> +
> +:- func string_builder_state_to_string(string_builder_state::di) = (string::uo)
> +    is det.

I would also provide to_string/1 as a synonym since that convention is
followed throughout much of the library.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list