prologswi-prologjpl

to load the same prolog file into different modules in jpl


I am trying to use jpl to load the same swipl file into different modules. The reason I had to do this is because I want to have a module that I can assert new predicates to, while leave the other untouched. Problem is swipl seems forbidding this,

jpl.PrologException: PrologException: error(permission_error(load, source, 'load.pro'), context(/(load_files, 2), 'Non-module file already loaded into module stable; trying to load into to_mess'))
    at jpl.Query.get1(Query.java:336)
    at jpl.Query.hasMoreSolutions(Query.java:258)
    at jpl.Query.oneSolution(Query.java:688)
    at jpl.Query.hasSolution(Query.java:759)

I have tried to set redefine_module(true) for load_files, but still no go

val query = new Query(s"load_files(${m}:'${loader}', [redefine_module(true)])")
query.allSolutions()

I have been blocked by this for hours, but cannot find a solution online. Can anybody please help??


Solution

  • You can use Logtalk running on SWI-Prolog + JPL to easily accomplish having two encapsulation units (objects instead of modules in this case) sharing a common initial definition (the contents of the file you're trying to load in two or more different modules). For the details of using Logtalk + SWI-Prolog + JPL see for example:

    https://github.com/LogtalkDotOrg/logtalk3/wiki/Using-Logtalk-with-JPL

    For the code sharing implied in your question, one solution is to put the contents of the file in an object and then derive from it (using inheritance) as many object as needed. For a more specific advice I would need more details on what you're trying to accomplish.