0

I have a prolog file that classifies a given predicate bongard(A, X) with given background facts. Snippet of the rules:

bongard(A,[neg]) :- triangle(A,C), \+ in(A,C,D), !. 
bongard(A,[neg]) :- \+ triangle(A,C), !. 
...

I am executing this program like so: swipl -s file.pl -g "bongard(a, X), write(X)", to obtain the classification for this predicate.

Now I would also like to know which rule triggered and actually bounded the variable. Is there any neat way to do this? Right now I need to keep an additional n files for an original prolog file with n rules. File1 has the first rule, file2 has the first 2 rules.. You get the idea. This way if File2 classifies the rule, I know the second rule fired.

Does anyone have any better suggestions for this?

EDIT: What about giving the predicate a unique number "bongard(A, X, nr)" I could then both write(X) and write(Nr) so I know which predicate fired?

false
  • 10,264
  • 13
  • 101
  • 209
xrdty
  • 886
  • 2
  • 10
  • 22

1 Answers1

0

Can you not just add an id number:

bongard(1,A,[neg]) :- triangle(A,C), \+ in(A,C,D), !. 
bongard(2,A,[neg]) :- \+ triangle(A,C), !. 
...

and then do (eg)

swipl -s file.pl -g "bongard(N,a,X), format('~w (rule ~w)~n',X,N)"
Tomas By
  • 1,396
  • 1
  • 11
  • 23