[m-dev.] Proposal: support for module initialisation and state

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Jul 8 21:16:12 AEST 2005




On Fri, 8 Jul 2005, Julien Fischer wrote:

> > MUTABLE STATE
> >
> > 	:- mutable(name, type, inst, initial_value).
> >
> > The mutable declaration can only appear in the implementation section of
> > a module and defines a mutable variable.  The compiler constructs access
> > methods
> >
> > 	:- semipure pred get_name(type::out(inst)) is det.
> > 	:- impure   pred set_name(type::in(inst)) is det.
> >
> > The set_name predicate trails the current value to ensure changes are
> > undone on backtracking.
> >
> > An untrailed_mutable declaration means the same as the mutable declaration
> > except that the set_name predicate does not trail the current value:
> >
> > 	:- untrailed_mutable(name, type, inst, initial_value).
> >
> Surely, :- mutable doesn't trail values in non .tr grades?
>
>
An alternative here may be to have :- mutable not trail the values,
and replace :- untrailed_mutable with :- trailed_mutable.  Using
:- trailed_mutable in non .tr grades could result in either a
compile or runtime error.

Also, what is the intended behaviour of these mutable states supposed
to be in multi-threaded environments.

Julien.
--------------------------------------------------------------------------
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