Using call/1 not a good idea, because call/1 actually names the goal, but you just want to find out if a fact / rule exists, and you donβt want to wait after a long calculation that the call may cause an error, and you donβt want to, so that something is printed on the screen, if the called rule, in turn, calls, for example, writeln/1 . In addition, you would like verify/2 succeed, even if the call failed (but this is actually a fact / rule).
As a solution, SWI-Prolog offers callable/1
callable(+Term) True if Term is bound to an atom or a compound term, so it can be handed without type-error to call/1, functor/3 and =../2.
Here are two versions of verify/2 , one of which is call/1 , and the other is callable/1 .
verify1(Name, Arguments) :- Term =.. [Name | Arguments], call(Term). verify2(Name, Arguments) :- Term =.. [Name | Arguments], callable(Term). father(abraham, isaac) :- writeln('hello'). father(abraham, adam) :- fail.
source share