Exclude certain predicates from a trace?

I’m using: SWI-Prolog version 8.0.2

@ericGT - Is predicate the correct term here? functor seems weird to me in this particular context. Should I use that instead? Or perhaps simply function?

Is there a way to exclude certain predicates from activating the debugger during a trace? For example, suppose I didn’t want consult() to activate the debugger even if I’m currently tracing, when I reconsult a file from the console?

See: What’s the difference between functor, a fact, a predicate and a rule in Prolog?

I personally choose to not use function when describing Prolog. I will sometimes use it to bridge the concepts from the functional programming world to logic programming but avoid the use of the word if possible.

In this question I would go with predicate as I am guessing that you want to exclude multiple clauses with the same name/arity.

1 Like

The difference between a term and a predicate (or goal) can be subtle. They look the same and are distinguished by context. For example:

foo(1).
foo(2).
foo_results(Results) :- setof(X, foo(X), Results).
?- foo_results(Results).
Results = [1, 2].

The predicate foo/1 has two clauses. The predicate foo_results/1 calls this, but indirectly … the setof/3 meta-predicate takes a term as its second argument, which it interprets as a predicate. In other words, a functor (name/arity) is the skeleton of a kind of term; some meta-predicates (e.g., call/1, setof/3, etc.) can interpret a term (functor/arity) as a predicate.

(BTW, in an earlier posting, I got this wrong, and still might not have some details of terminology correct.)

In your case, I’d say that “exclude certain predicates” is correct and understandable; but technically speaking, you specify the “certain predicates” using terms (you don’t actually call the predicates but use their name/arity to specify them).

2 Likes

The use of the word specify caught me off guard, I had to pull out the ISO Prolog specification and search for the word. I am use to the word execute.

3.67 execution (verb: to execute): The process by which a Prolog processor tires to satisfy a goal (see 7.7.1).

7.7.1 Execution

Execution is a sequence of activations which attempt to satisfy a goal. Side effects (7.7.9) may occur during execution.

Each execution step is represented by a sequence of
execution states.

Call is mostly noted as call/1

7.8.3 call/1

7.8.3.1 Description

call(G) is true iif G represents a goal which is true.

I didn’t mean “specify” in any technical sense; and certainly not in any ISO-Prolog sense.

Anyway, perhaps this example will help:

times(0, 10, 0).  % A trivial predicate for this example
times(1, 10, 10).
times(2, 10, 20).

append_arg_and_call(Call, Arg) :-
    Call =.. CallList,
    append(CallList, [Arg], CallPlusArgList),
    CallPlusArg =.. CallPlusArgList,
    call(CallPlusArg).

And running it:

?- append_arg_and_call(times(1, 10), Z).
Z = 10.

The call to eval/2 passes in the term times(1,10), which gets an additional argument added to it before it’s called. In a functional programming language, you’d create a “closure” or “partial function”, but in Prolog, it’s just a term that is interpreted by the call predicate to execute a goal (“execute” in the ISO-Prolog sense).

?- trace, append_arg_and_call(times(1, 10), Z).
   Call: (10) append_arg_and_call(times(1, 10), _2522) ? 
   Call: (11) times(1, 10)=.._2844 ? 
   Exit: (11) times(1, 10)=..[times, 1, 10] ? 
   Call: (11) lists:append([times, 1, 10], [_2522], _2870) ? 
   Exit: (11) lists:append([times, 1, 10], [_2522], [times, 1, 10, _2522]) ? 
   Call: (11) _2884=..[times, 1, 10, _2522] ? 
   Exit: (11) times(1, 10, _2522)=..[times, 1, 10, _2522] ? 
   Call: (11) times(1, 10, _2522) ?              % <=== executes the *goal*
   Exit: (11) times(1, 10, 10) ? 
   Exit: (10) append_arg_and_call(times(1, 10), 10) ? 
Z = 10.

(Normally, you wouldn’t define append_arg_and_call/2 because the builtin call/2 handles appending an arg; I wrote a pure-Prolog implementation to show you that it takes a term, manipulates that term, and finally interprets the manipulated term as a goal.)

1 Like