[m-rev.] Add `:- mutable' declaration to the language.
Julien Fischer
juliensf at cs.mu.OZ.AU
Thu Sep 1 17:14:05 AEST 2005
On Thu, 1 Sep 2005, Ralph Becket wrote:
> Index: doc/reference_manual.texi
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
> retrieving revision 1.322
> diff -u -r1.322 reference_manual.texi
> --- doc/reference_manual.texi 29 Aug 2005 03:22:28 -0000 1.322
> +++ doc/reference_manual.texi 1 Sep 2005 03:48:07 -0000
> @@ -558,6 +558,7 @@
> :- pragma
> :- promise
> :- initialise
> +:- mutable
> :- module
> :- interface
> :- implementation
> @@ -4237,6 +4238,7 @@
> * An example module::
> * Sub-modules::
> * Optional module initialisation::
> +* Module-local mutable variables::
> @end menu
>
> @node The module system
> @@ -4582,6 +4584,44 @@
> order in which they are specified, although no order may be assumed between
> different modules or submodules.
>
> + at node Module-local mutable variables
> + at section Module-local mutable variables
> +
> +Certain special cases require a module to have one or more mutable (i.e.
> +destructively updatable) variables, for example to hold the constraint
> +store for a solver type.
> +
> +A mutable variable can be declared in the implementation section of
> +a module using the @samp{mutable} directive:
> +
s/can/is/
> + at example
> +:- mutable(varname, vartype, initial_value, varinst, [attribute, ...]).
> + at end example
> +
> +This has the effect of constructing a new mutable variable with access
> +predicates with the following signatures:
> +
How about:
This constructs a new mutable variable with access predicates
that have the following signatures.
> + at example
> +:- semipure get_varname(vartype::out(varinst)) is det.
> +:- impure set_varname(vartype::in(varinst)) is det.
> + at end example
> +
> +The initial value of @samp{varname} is @samp{initial_value}, which is set
> +before the program's @samp{main/2} predicate is executed. The type
> + at samp{vartype} is not allowed to contain any type variables and the inst
> + at samp{varinst} is not allowed to contain any inst variables or have any type
> +class constraints; @samp{initial_value} can be any Mercury expression with
> +type @samp{vartype} and inst @samp{varinst}.
> +
> +The possible @samp{attributes} are @samp{thread_safe}, meaning that
> +access to the mutable need not be protected in parallel grades, and
> + at samp{untrailed}, meaning that the effects of calls to
> + at samp{set_varname/1} should not be undone on backtracking.
> +
You may wish to put a pointer to the discussion of thread_safe for
foreign_procs here since it means the same thing and there is more
detail provided there.
> +C code in the same module can access the mutable variable using the name
> + at samp{mutable_variable_varname}, which is a global variable with type
> + at samp{MR_Word}.
> +
s/C code/Foreign code/ since we may one day implement these for the
other backends.
The rest of that changes looks ok.
Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list