how to consult file as a module in jpl

我只是一个虾纸丫 提交于 2019-12-11 06:27:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!