How do you selectlively (auto)load pieces of the SWI Prolog library?

I’m using: SWI-Prolog version: latest stable

I am coding some graph stuff, but the library ugraph gets autoloaded and causes conflicts.
How can I prevent the library to be autoloaded or at least “imported” automagically? I.e., how do I force - at a minimum - the use of the ugraph:: qualifier?

Thanks

Marco

A library only gets autoloaded if you omitted some declaration that is provided by this library. You simply prevent autoloading by making sure your application defines everything it needs.

The built-in editor highlights in red all calls that are not satisfied and in a little darker blue then built-in and imported stuff for predicates that will be autoloaded. Click on the call to see where it will be autoloaded from and decide whether or not you want that.

In the development version you can disable autoloading meaningfully. The stable version mostly get useless. The built-in editor there has some extra commands to deal with (library) dependencies such as ^c^d, which updates the list of dependencies in the file. If you do not like some dependency, right click it to check which predicates it resolves.

Even if you do not like the built-in editor, it can be very useful to check your code. Another option is library(check), which exports check/0 and a couple of related predicates.

1 Like

Thanks

Actually I may be in a slightly more complicated bind than just using the editor. I am actually loading students’ code in a batch mode running PLUnit, and I want to minimize their “creativenessity” :slight_smile:

Let me see how much mileage I get get and I will report back here.

all the best

Marco

Hi

I am still fighting with this issue. I am sorry, but whatever I tried in the time since my first post is not working.

The question remains.

How do I force SWI Prolog not to autoload or, at a minumum, force fully qulified names for certain libraries?

Any help will be appreciated.

Thanks

Marco

I would guess you could use the development version (8.3.X) and run set_prolog_flag(autoload,false), before loading the students code. See current_prolog_flag/2.

It is still pretty unclear to me why you want that in the first place. You do not want students to use the library or be explicit about this? Using module:goal is bad practice given the design of the module systems as explained in What is the best practice for "namespacing" imports?

If you want to prevent or know which library predicates are used you can use the cross referencer (library(prolog_xref)), load and test the program in a module (done anyway for the unit tester) and check this module after loading an running the program for predicates that are imported from the library, e.g.

 predicate_property(M:Goal, imported_from(File)).

And most likely there are several more ways :slight_smile:

Dear Jan

I want a way to say

:- do_not_autoload([ugraph, heaps]).

and having the system not autoload (read: not importing automatically) the predicates in the current session.

I understand that this may be difficult to achieve, and, given the explanation you pointed to, even more so. Yet, I believe it would make a lot of sense.

All the best

Marco

A do_not_autoload appears to me as a recipe for more confusion. The options are fairly simple: use the 8.3.x series and disable autoloading or detect autoloading has been used. It is unclear to me to what problems this leads. I guess it also depends on how your students get access to SWI-Prolog.

Thank you Jan

after some thought and after reading your other message, I guess that it will be easier for me to revise the assignment. Unfortunately I cannot have the “average” student delve too deeply in the use advanced SWI Prolog features.

Thank you again

all the best

Marco