Re: communicate with Prolog engine in Prolog
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 10 Dec 2007 16:33:11 GMT
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
.
- Follow-Ups:
- Re: communicate with Prolog engine in Prolog
- From: Simon Strobl
- Re: communicate with Prolog engine in Prolog
- References:
- communicate with Prolog engine in Prolog
- From: Simon Strobl
- Re: communicate with Prolog engine in Prolog
- From: Martin Riener
- Re: communicate with Prolog engine in Prolog
- From: Simon Strobl
- Re: communicate with Prolog engine in Prolog
- From: Martin Riener
- communicate with Prolog engine in Prolog
- Prev by Date: Re: communicate with Prolog engine in Prolog
- Next by Date: Re: RDF?
- Previous by thread: Re: communicate with Prolog engine in Prolog
- Next by thread: Re: communicate with Prolog engine in Prolog
- Index(es):
Relevant Pages
|
|