Różnice

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

Odnośnik do tego porównania

pl:prolog:pllib:pattern_interpreter [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Pattern interpreter ======
 +{{tag>​patterns interpreter}}
 +===== Description =====
 +A small interpreter for pattern-directed programs.
 +
 +**Source**: ​ PROLOG programming for artificial intelligence,​ 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7.
 +===== Download =====
 +Program source code: {{pattern_interpreter.pl}}
 +===== Listing =====
 +<code prolog>
 +%  Figure 23.13  A small interpreter for pattern-directed programs.
 +
 +
 +%   A small interpreter for pattern-directed programs
 +%   The system'​s database is manipulated through assert/​retract
 +
 +
 +:-  op( 800, xfx, --->).
 +
 +% run: execute production rules of the form
 +%      Condition ---> Action until action `stop' is triggered
 +
 +run  :-
 +  Condition ---> Action, ​        % A production rule
 +  test( Condition), ​             % Precondition satisfied?
 +  execute( Action).
 +
 +% test( [ Condition1, Condition2, ...])  if all conditions true
 +
 +test( []).                       % Empty condition
 +
 +test( [First|Rest]) ​ :-          % Test conjunctive condition
 +  call( First),
 +  test( Rest).
 +
 +% execute( [ Action1, Action2, ...]): execute list of actions
 +
 +execute( [ stop]) ​ :-  !.         % Stop execution
 +
 +execute( [])  :-                 % Empty action (execution cycle completed)
 +  run.                           % Continue with next execution cycle
 +
 +execute( [First | Rest]) ​ :-
 +  call( First),
 +  execute( Rest).
 +
 +replace( A, B)  :-               % Replace A with B in database
 +  retract( A), !,                % Retract once only
 +  assert( B).
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/pattern_interpreter.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