fig23_2.pl

来自「超多的prolog源代码 具体内容见压缩包里面的programs.txt」· PL 代码 · 共 37 行

PL
37
字号
%  Figure 23.2  A Prolog meta-interpreter for tracing programs
%  in pure Prolog.


% trace( Goal): execute Prolog goal Goal displaying trace information

trace( Goal)  :-
  trace( Goal, 0).

trace( true, Depth)  :-  !.                      % Red cut; Dept = depth of call

trace( ( Goal1, Goal2), Depth)  :-  !,           % Red cut
  trace( Goal1, Depth), 
  trace( Goal2, Depth).

trace( Goal, Depth)  :-
  display( 'Call: ', Goal, Depth),
  clause( Goal, Body),
  Depth1 is Depth + 1,
  trace( Body, Depth1),
  display( 'Exit: ', Goal, Depth),
  display_redo( Goal, Depth).

trace( Goal, Depth)  :-                          % All alternatives exhausted
  display( 'Fail: ', Goal, Depth),
  fail.

display( Message, Goal, Depth)  :-
  tab( Depth), write( Message),
  write( Goal), nl.

display_redo( Goal, Depth)  :-
  true                                           % First succeed simply
  ;
  display( 'Redo: ', Goal, Depth),               % Then announce backtracking
  fail.                                          % Force backtracking  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?