Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:all_solutions [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== All solutions ======
 +{{tag>​searching knowledge_base}}
 +===== Description =====
 +Implementing an all-solutions predicate using difference-lists,​ assert and retract
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{all_solutions.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 +   ​find_all_dl(X,​Goal,​Instances) :- Instances is the multiset
 + of instances of X for which Goal is true. The multiplicity
 + of an element is the number of different ways Goal can be
 + proved with it as an instance of X.
 +*/
 + :- op(40,​xfx,​\).
 +
 + find_all_dl(X,​Goal,​Xs) :-
 + asserta('​$instance'​('​$mark'​)),​
 + Goal,
 + asserta('​$instance'​(X)),​
 + fail.
 + find_all_dl(X,​Goal,​Xs\Ys) :-
 + retract('​$instance'​(X)),​
 + reap(X,​Xs\Ys),​ !.
 +
 + reap(X,​Xs\Ys) :-
 + X \== '​$mark',​
 + retract('​$instance'​(X1)),​ ! ,
 + reap(X1,​Xs\[X|Ys]).
 + reap('​$mark',​Xs\Xs).
 +
 +% Program 16.3 : Implementing an all-solutions predicate using
 +% difference-lists,​ assert and retract
 +
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/all_solutions.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0