ISO directive: initialization. This should work.
:- initialization main.
main :-
write('Hello World\n').
edit sorry, I skipped over most interesting details. Here is a sample script, let’s say saved in ~/test/main.pl
#!/home/carlo/bin/swipl -f -q
:- initialization main.
main :-
current_prolog_flag(argv, Argv),
format('Hello World, argv:~w\n', [Argv]),
halt(0).
and made executable with
chmod +x ~/test/main.pl
then I get
~$ ~/test/main.pl
Hello World, argv:[]
~$ ~/test/main.pl as,dnj asdl
Hello World, argv:[as,dnj,asdl]
In script main.pl
, I used the swipl path that results from building from source without admin privileges. The SWI-Prolog build process put bin and lib under ~/bin and ~/lib
Note: the -f flag disables loading the initialization ~/.plrc, and this could be necessary to get more ‘strict control’ over execution…
I’m currently unsure if the documentation page is up-to-date with current SW status. From some mailing list message, and my own efforts to reuse thea, seems that command line flags changed recently…