-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC: New program initialization handling.
- Loading branch information
Jan Wielemaker
committed
Jun 6, 2017
1 parent
a637b68
commit 17d7e1f
Showing
4 changed files
with
58 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
Author: Jan Wielemaker | ||
E-mail: [email protected] | ||
WWW: http://www.swi-prolog.org | ||
Copyright (c) 2002-2016, University of Amsterdam | ||
Copyright (c) 2002-2017, University of Amsterdam | ||
VU University Amsterdam | ||
All rights reserved. | ||
|
@@ -49,7 +49,7 @@ | |
== | ||
#!/usr/bin/env swipl | ||
:- initialization main. | ||
:- initialization(main, main). | ||
main(Argv) :- | ||
echo(Argv). | ||
|
@@ -71,7 +71,9 @@ | |
|
||
%! main | ||
% | ||
% Call main/1 using the passed command-line arguments. | ||
% Call main/1 using the passed command-line arguments. Before calling | ||
% main/1 this predicate installs a signal handler for =SIGINT= | ||
% (Control-C) that terminates the process with status 1. | ||
|
||
main :- | ||
context_module(M), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17d7e1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid so many uses of
main
(with different meanings) which are likely to cause confusion, I have one naming suggestion for the user-defined predicate in these examples:run/0
.The directives in the sample code would then become:
17d7e1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do admit that
initialization(main, main).
can be a little confusing. The firstmain
comes fromlibrary(main)
. I'm reluctant changing this torun/0
.main
is the generally used name for entrypoints. We could also rename the initialization type. I doubt
run
is better though.17d7e1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I name all such entry points
run/0
in my programs. I have many, many test cases, which I all invoke like this. They run, and run, and run!17d7e1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing stops you from using
:- initialization(run, main).
:)main/0
doesn't do that much. Only collecting the arguments (which is really easy) and rebind Control-C to stop the application. This whole thing has been a nuisance for quite a while to me. I'm glad it is resolved. Will updatehttp_unix_daemon.pl
accordingly, so your config + proxy should work fine.17d7e1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thank you very much!
17d7e1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Seems
http_unix_daemon.pl
asks the user to useinitialization/1
. This isn't a great advice any longer. I see two options::- initialization(http_daemon, main).
In both cases old code will keep working as it will simply call the non-returning (half functional)
:- initialization(http_daemon).
In both cases you can define your own using an explicitWhat do you think? It may depend on Eyal's reply. If he comes with a convincing argument to only honour main initialization from the script argument file(s), putting it inside is no option. If that doesn’t change I think my preference is to put the initialization/2 call inside the library. After all, there is no application for this library except for managing an HTTP server as an application.
17d7e1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the HTTP Unix daemon, I think it is particularly important to guarantee:
There may also be other important guarantees that are worth to ensure (and which probably even already hold now thanks to your patches), but the two above are those that come to mind immediately because they were previously not satisfied (SWI-Prolog/packages-http#71).
For backwards compatibility, it is definitely a big plus that
initialization/1
as previously recommended can still be used, with the same (albeit broken) results as previously. However, if this stands in the way of more desirable guarantees, then it can as well be removed in my view, and moved into the library itself.17d7e1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I scan through SWI-Prolog/packages-http#71, both issues were caused by the initialization/1 goal not returning. These should be fixed using the new way to declare the entry point. I think the ways to make the program depending on the loading order remaining are:
the case for the registered HTTP handlers and that is why a priority is used to create a handler
that overrules another.
I'll add the initialization to the library. This isn't all set in stone yet. If anyone comes in with a good suggesting in the next week or so, things will change.