Różnice

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

Odnośnik do tego porównania

pl:prolog:pllib:rule_interpreter_3 [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Rule interpreter 3 ======
 +{{tag>​rule interpreter framework}}
 +===== Description =====
 +A skeleton two-level rule interpreter
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{rule_interpreter_3.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 +       ​monitor(Goal) :-
 +           ​Succeeds if a result of yes is returned from solving Goal
 +          at the solve level, or when the end of the computation is reached.
 +*/
 +
 +:- op(40,​xfy,&​).
 +:- op(30,​xf,​is_true).
 +
 +       ​monitor(Goal) :-  solve(Goal,​Result),​ filter(Result).
 +       ​monitor(Goal).
 +
 +       ​filter(yes).
 +       % filter(no) ​  fail.
 +
 +/*
 +       ​solve(Goal,​Result) :-
 +           Given a set of rules of the form rule(A,​B,​Name),​ Goal has
 +           ​Result yes if it follows from the rules and no if it does not.
 +*/
 +       ​solve(A,​yes) :-  fact(A).
 +       ​solve(A,​Result) :-  rule(A,​B,​Name),​ solve_body(B,​Result).
 +       ​solve(A,​no).
 +
 +       ​solve_body(A&​B,​Result) :-
 +           ​solve(A,​ResultA),​ solve_and(ResultA,​B,​Result).
 +       ​solve_body(A is_true,​Result) :-   ​solve(A,​Result).
 +
 +       ​solve_and(no,​A,​no).
 +       ​solve_and(yes,​B,​Result) :- solve(B,​Result).
 +
 +%   ​Program 17.18: A skeleton two-level rule interpreter
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/rule_interpreter_3.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