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

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Jul 8 17:04:54 AEST 2005


On Fri, 8 Jul 2005, Ralph Becket wrote:

> It's becoming apparent that some modules need (a) initialization of some
> kind (e.g., when interfacing with OpenGL or CPLEX) and/or (b) support
> for module-local mutable state (e.g., to hold constraint stores for
> solver types).
>
> I propose we add something like the following to the language (the
> syntax is purely conjectural; it would be good if we could agree on the
> functionality and semantics before we start the obligatory syntax war :-)
>
> INITIALISATION AND FINALISATION
>
> 	:- initialisation(pred_name).
>
> Ensures that at start-of-day (i.e., before main is called)
> pred_name(!IO) is called.  No initialisation order can be assumed.
>
I think that the program should also abort if one of the initialisation
predicates sets the exit status to non-zero (or at the least there should
be some other mechansim that allows the program to abort gracefully
if initialisation fails.)

> 	:- finalisation(pred_name).
>
> Ensures that at end-of-day (i.e., after main has returned)
> pred_name(!IO) is called.  No finalisation order can be assumed.
>

We should be able to assume an order within modules; between modules
(and submodules?) no.

Both of these declarations hould only be able to appear in the
implementation section of a module.


> 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?


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