[m-dev.] [refman] Mutable variables example

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Sat May 27 08:04:33 AEST 2006

Dear all,

Hi!  The refman is exact in describing module mutable variables
(section 9.6) but does not provide an example.  So, for example,
I had a misunderstanding with the mutable variable name (I used
an uppercase first character on the first go).

I request the documentation be enhanced with an example ... 
something like the following:

:- module mutemebaby.

:- interface.

:- import_module io.

:- pred main(io::di, io::uo) is det.

:- implementation.
:- import_module list, string.

:- mutable(mutant, int, 0, ground, []).
:- mutable(io_mutant, int, 0, ground, [attach_to_io_state]).

:- pragma promise_pure(main/2).

main -->
	impure main2,

:- impure pred main2(io, io).
:- mode main2(di, uo) is det.

main2 -->
	{ semipure get_mutant(M0) },
	format("Hey, mutant is %d\n", [i(M0)]),
	{ impure set_mutant(2),
	  semipure get_mutant(M1) },
	format("Hey, mutant is now %d\n", [i(M1)]).

:- pred main3(io::di, io::uo) is det.

main3 -->
	format("Hey, io_mutant is %d\n", [i(M0)]),
	format("Hey, io_mutant is now %d\n", [i(M1)]).

:- end_module mutemebaby.

Sorry, I don't have a `diff -u` against the refman, but
I don't have tools to modify Tex or DVI.

What are the real-world cases for mutable variables where their
initial instantiation would be something other than ground?

Doug Auclair

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