Search code examples
prologprolog-metainterpreter

No permission to access private_procedure `true/0'


I am trying to use vanilla meta interpreter with 'if' and 'and'.

Here is my code:-

:- op( 600, xfy, if).
:- op( 500, xfy, and).
findnum(X,X).
findnum(X,[X|Tail]).
findnum(X,[Y|Tail]):-
   findnum(X,Tail).

prove(true).
prove((A,B)):- !,prove(A),prove(B).
prove(A and B):-
   !,prove(A),prove(B).
prove(A):-
   clause(A,B),
   prove(B).

when both condition true.

?-prove((findnum(a,[a,b,c]) and findnum(a,[a,b,c]))).
true

when first condition false.

?-prove((findnum(a,[b,b,c]) and findnum(a,[a,b,c]))).
false

but when second condition is false it return error No permission to access private_procedure `true/0'

?-prove((findnum(a,[a,b,c]) and findnum(a,[b,b,c]))).
ERROR: No permission to access private_procedure `true/0'

please help, thank you.


Solution

  • The error results from trying to call the clause/2 predicate on built-in predicates. A minimal fix would be to modify the first clause of your meta-interpreter:

    prove(true) :- !.
    

    This will avoid backtracking on prove(true) goals to try to use the last clause of the meta-interpreter, resulting in that error. A more general fix is to add the following clause:

    prove(A) :-
        predicate_property(A, built_in),
        !,
        call(A).
    

    I.e.

    prove((A,B)):-
        !,
        prove(A),
        prove(B).
    prove(A and B):-
       !,
       prove(A),
       prove(B).
    prove(A) :-
        predicate_property(A, built_in),
        !,
        call(A).
    prove(A):-
       clause(A,B),
       prove(B).