问题
I am trying to consult Prolog file as a module, since jpl does not support multiple prolog vms.
In swipl console, I can do something like this successfully
?- consult(mod1:'data/load.pro') .
In java (well, it is actually scala, but they are all on top of jvm), I can consult file directly w/o issue
scala> import jpl._
scala> val q = new Query("consult", Array[Term](new Atom("data/load.pl")))
scala> q.query()
...
true
however, when I tried to consult the file as module, I always get the exception.
scala> val q = new Query("consult", Array[Term](new Atom("mod1:data/load.pl")))
scala> q.query()
jpl.PrologExcepion: PrologException: error(existence_error(source_sink, 'mod1:data/load.pl'), _0)
at jpl.Query.get1(Query.java:336)
at jpl.Query.hasMoreSolutions(Query.java:258)
at jpl.Query.oneSolution(Query.java:688)
at jpl.Query.query(Query.java:747)
at .<init>(<console>:15)
at .<clinit>(<console>)
....
Anybody can point me to the correct way of consulting prolog file as module in jpl? Thanks!
回答1:
I think you can swap the module qualification on predicate, and of course that would allow you to pass in the full path of your source file:
val q = new Query("mod1:consult('full_path_to/load.pl')")
来源:https://stackoverflow.com/questions/17837467/how-to-consult-file-as-a-module-in-jpl