[mercury-users] Automatic module initialisation?

Warwick Harvey wharvey at cs.monash.edu.au
Mon Feb 22 11:31:40 AEDT 1999


Fergus wrote:
> On 19-Feb-1999, Warwick Harvey <wharvey at cs.monash.edu.au> wrote:
> > 
> > Is it possible to get Mercury to automatically call an initialisation 
> > predicate/function for a module at start-up?
> 
> You and Peter Schachte have been plotting together, haven't you? ;-)

Ummm...  No comment.  :-)

(Actually, I'd forgotten that the subject had been discussed --- at the time 
I had no particular interest in doing this, so didn't really pay much 
attention.)

> Out of curiousity, why do you need an initialisation function?

Well, HAL has ``global variables''.  In HAL, the user provides 
initialisation code for these in their declarations, so that they always 
have a valid value at any point in the ``main'' body of code.  It is 
intended that usually these ``global'' variables will be hidden inside 
modules, with the user of such modules not having to know that they are 
there.  Hence we want some automatic way to have this initialisation code 
executed without the author of ``main'' having to do it.

Of course we could do something similar to Mercury's c2init, but why bother 
if we can (continue to) piggy-back off Mercury?  :-)  Though if you can 
think of some better way of managing this, I'd be happy to hear about it.

(For those who don't know, HAL is a constraint logic programming language 
which [almost] compiles to Mercury.)

(And is the web mailing list search facility broken?  I tried searching for 
[in turn] "initialisation", "initialization", and "module" and it came up 
blank for each...  I'd like to read the old discussion, but can't find it.  
[Hmm, maybe it's time to ditch the web and pull out "fgrep" ;-]).

> Of course, if you rely on this, then you are
> relying on implementation details that could perhaps change in some
> future release.

Understood.

> Using an "INIT' line in the C code is not enough; you have to also use
> the `--extra-inits' and the `--include-initialization-code' options,
> as you did, and in addition your program startup then needs to call
> the function do_init_modules(), which is declared in one of the
> header files included by "mercury_imp.h".

Yes, the call to do_init_modules() has (temporarily :-) fixed the problem, 
thanks.

Warwick




More information about the users mailing list