'Resetting' consulted files with JPL

Hey there. This is my very first experience using Prolog, and I’m doing so through JPL. To summarize what I’m trying to achieve, I want to be able to swap between using different source files with regularity due to the nature of my program, which models the sharing of knowledge between agents.

Lets say I consult an agent’s knowledge base and query it for the presence of a predicate, independent from other knowledge bases, then repeat for all agents. Currently, each consult seems to include new predicates alongside any previously loaded, meaning if the predicate is found in one knowledge base, the following queries will all detect its presence. I need only one knowledge base to be considered at a time, and I’m clearly missing something in how these queries work.

I’m aware that re-initialization is not supported by JPL, and you can only have one Prolog instance at a time (in a single thread?), so I tried multi-threading, each thread existing to consult and query a different knowledge base once, so each thread could use a Separate SWI Prolog engine. I feel like this is close to what I want, but my issue persists. I’ve tried using unload_file, didn’t change anything. I suppose I could try to retract all predicates every time I want to reset?

Is there a better way to achieve what I’m aiming for?

1 Like

Threads share the program, so that will not work. Normally unload_file/1 should do the job. We’d need more detail to get an idea why not in this case. I also wonder what “presence of a predicate exactly means”? The normal solution would be to load the agent’s knowledge into a module. That also allows having the knowledge of multiple agents in memory at the same time. It isn’t really “beginner” stuff though and going through JPL doesn’t make it easier either.

Roughly, you do consult(my_module:'myfile.pl') and then call things as my_module:my_goal(...)


By ‘presence of a predicate’, I just meant boolean for the fact being included in the currently queried knowledge base.

Thank you for informing me on the threads, I scrapped the multi-threading. Turns out in my late-night haste I wasn’t actually running the unload query with .allSolutions, hence I don’t think the query was ever closing.

Additionally, I overlooked the arity of unload_file, and was actually attempting to unload two files at the same time - I was consulting two knowledge bases at once for one of my earlier queries by combining the filenames into a single string and using JPL’s textToTerm to make the query, forgetting to separate them for the unload.

Rectifying this should be enough to achieve everything I want to, but if not I will look further into modules. Cheers Jan!