scryer-prolog
scryer-prolog copied to clipboard
use_module/1 doesn't respect changes in current working directory if executed as initialization goal
As in title. I found it when I tried to use modules from a different folder for #2435.
Contents of ~/.scryerrc
:
:- use_module(library(iso_ext)).
:- use_module(library(files)).
:- use_module(library(lists)).
:- use_module(library(os)).
use_custom_modules(Ms) :-
getenv("SCRYER_LIBRARY_PATH", LD),
setup_call_cleanup(
working_directory(WD, LD),
maplist(use_module, Ms),
working_directory(_, WD)
).
Put some dummy module foo.pl
into $SCRYER_LIBRARY_PATH
:
:- module(foo, []).
Put user.pl
file into any folder different from $SCRYER_LIBRARY_PATH
for example to /tmp. Contents of user.pl
:
:- initialization(use_custom_module([foo]))
Make sure that $SCRYER_LIBRARY_PATH
is exported and run Scryer:
# echo $SCRYER_LIBRARY_PATH
/home/hurufu/Projects/prolog-utils
# pwd
/tmp
# scryer-prolog user.pl
error(existence_error(source_sink,"/tmp/foo.pl"),open/4).
?- use_custom_modules([foo]).
true.
As you see if I execute use_custom_modules/1
from the top level – it works ok, but it throws an exception if it is called during initialization. I would expect initialization goal to succeed and it should use the correct path.