Re: running once at true startup

Jan Wielemaker <[email protected]> Wed, 9 Apr 2014 09:58:05 +0200
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 09-04-14 09:38, Anne Ogborn wrote:
> I'm working on a mud with a couple folks, and we've got a question about the right way to
> do things.
> 
> When we start up, we want it, naturally enough, to run the game. So we have some
> 
> :- run_the_game.
> 
> in the startup file.
> 
> inside the game we've got a command that gets you back to the prolog prompt for development.

Doesn't that happen simply because run_the_game/0 basically just starts some
server threads and than succeeds?

P.s. This typically should be

:- initialization run_the_game.

Standard Prolog does not allow for arbitrary calls as directives.
SWI-Prolog
does, but the difference is that initialization goals are executed *after*
loading of the file has completed rather than during loading.  Often, it
doesn't matter too much, but sometimes it does because loading files
involves
global state wrt. I/O, locks, etc.

> This is all hunky dory, until you modify a file and run make. now the game gets started again!

Only if you modify the startup file itself or if you load the startup
file from another file that is modified using an unconditional load
predicate such as :- [startup].

> Whats the proper way to handle this sort of behavior?

I guess either check in the directive that the thing is not already
running or put these directives in a file that is so simple that you
never need to modify it.  E.g., make a startup.pl like this:

:- initialization run_the_game.
:- use_module(mygame).

That said, SWI-Prolog has initialization/2.  Maybe we should add

:- initialization(run_the_game, once).

where `once` would mean the same as `after_load`, but in addition
does not execute the directive on reloads.  Would that make sense?

	Cheers --- Jan


> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>