Problems getting custom initialization file to work on Linux?

PREFACE: I’m using: SWI-Prolog version 8.0.3. If this is a problem specific to that version please let me know and I’ll go ahead and upgrade to one of the 8.1.x version.

I am trying to create my own custom initialization file. First I found the file named /usr/lib/swi-prolog/swipl.rc. I then copied it to a file named “swipl-for-linux.ini”. I then made a simple modification to my copy that added a sign-on message so I could know that my initialization file had been executed. Here are the lines I appended to my custom initialization file:

% Write a custom sign-on message so we know this file executed.
:- write("Welcome to PEngines."), nl, !.

initmsg :-
	write("Welcome to PEngines."),
	!.

I then tried to load SWI-Prolog using the command line option to use my initialization file instead of the default one:

swipl -f ./swipl-for-linux.ini

But this led to the following error at the command line:

ERROR: Prolog initialisation failed:
ERROR: module/2: No permission to redefine module `link_xpce' (Already loaded from /usr/lib/swi-prolog/swipl.rc)

This tells me that the default initialization file is still getting executed. I then tried the site wide flag:

swipl -F ./swipl-for-linux.ini

SWI-Prolog did load this time, but did not show my sign-on message. So I tried running the predicate I defined in my ini file named initmsg as another test, but I got an error indicating it was never defined. I then tried putting some phony names for the “-f” argument and discovered that SWI-Prolog does not complain if you give it a bad file name for the custom initialization file. So my iilusory success with the “-F” flag indicates that it failed to load my initialization file like it did do with the “-f” flag.

How can get SWI-Prolog to ignore the default initialization file and use my initialization file instead?

TYPO ON DOCUMENTATION PAGE:

I have been using the following documentation page for this project:

https://www.swi-prolog.org/FAQ/PlInitialisation.html

I found a typo:

  • “explicitely” is misspelled. It should be “explicitly”

The system wide init file links the graphics system if available. You disable that using -F none,
which rarely makes sense unless you want to create a minimal stand-alone binary. You could in theory add other system-wide init files to the installation, but I doubt it is ever done. The whole thing has become a bit obsolete.

Personal initialization is pretty much covered in the manual. Create the required file. You can use -f file where this file should really exist to load a specific file without the user initializiation. Also that can make some sense to create executables without stuff to help development for the current user. Typically you just start an application using

 swipl file.pl

and do not touch the whole initialization. You create an init file if you want to change the editor, history and similar defaults.

1 Like

Thanks Jan. I’ll move the code in the initialization file out of there and make it a predicate in a new source file. Then I’ll use the “-s” command line option to auto-run that script when I start my PEngines server.