fig23_13.pl
来自「超多的prolog源代码 具体内容见压缩包里面的programs.txt」· PL 代码 · 共 40 行
PL
40 行
% 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).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?