Re: communicate with Prolog engine in Prolog



On 2007-12-10, Martin Riener <martin.riener@xxxxxxxxx> wrote:
Simon Strobl wrote:
for nonterminating predicates you could write a metainterpreter and stop
/pause after finding n variable substutions.

Even when the predicate does not terminate it may be useful to use
something like a metainterpreter.
Suppose users may query a Prolog program through a web interface.
Suppose a query has 530 solutions. Then the web-interface program
should talk to a Prolog engine E and get from E the first, say, 10
solutions. Only if the user wants more solutions, should the interface
program be given the next 10 solutions. It would be absurdly expensive
to calculate all 530 solutions in the first place.

one drawback of metainterpreters is that there is a noticable increase
in execution time, but since you plan to call from a cgi script, you
have to take (possibly infinite) execution time into account anyway :)

But why would you need a meta-interpreter in the first place? If you
write a cgi-script that must produce the first 10 results you can do

:- dynamic
found/1,

script :-
assert(found(0)),
( generate_solution(Solution),
write_solution(Solution),
retract(found(Old)),
New is Old + 1,
assert(found(New)),
New == 10, !,
retractall(found(_))
; retractall(found(_))
).


(untested). This is all standard ISO Prolog. In many specific Prolog
systems you can do better. On the link below you find bounded
backtracking predicates we use in a project. Lots of the code is
SWI-Prolog specific and most is certainly not library-quality, but
they might help you.

http://gollem.science.uva.nl/git/ClioPatria.git?a=blob;f=util/util.pl;h=fa37b8d2a523c89829cd0eeaef6a5620a3ba3868;hb=HEAD

--- Jan
.



Relevant Pages

  • Re: splitting lists
    ... In Prolog, you describe relations; ... languages, you introduce an additional argument in a ... Now you can query: ...
    (comp.lang.prolog)
  • Re: communicate with Prolog engine in Prolog
    ... Interfaces from other programming languages L to Prolog usually enable ... findall/3 (assuming the predicate terminates). ... for nonterminating predicates you could write a metainterpreter and stop ...
    (comp.lang.prolog)
  • Re: Sublists question
    ... I do not really get what the predicate means or does. ... >>helps just to write the predicate out clearly in natural language, ... >>then translate into Prolog. ... more as a functional programming language than as a logic ...
    (comp.lang.prolog)
  • Re: Prolog module system
    ... I think prolog offers so much freedom that one can build its own ... Both modules define a member/2 predicate, ... this leads to a name conflict. ... shaky ground as current module systems (look at the issues with e.g. ...
    (comp.lang.prolog)
  • Re: Prolog, memory management and memory leaks
    ... predicate is executed that solves constraint problem. ... In some circumstances, this server leaks memory. ... "Understanding Memory Management in Prolog ... There is not just one garbage collector in Prolog. ...
    (comp.lang.prolog)