Convert app(_12282,_12284,_12286) to app(_,_,_) for printing

After reading reply by Jan W. below.

For a predication use

?- functor(Predication,app,3),numbervars(Predication,0,_,[singletons(true)]).
Predication = app(_, _, _).

For a head use

?- functor(Head,app,3),numbervars(Head).
Head = app(A, B, C).

See: What is the difference between head and predication.


Earlier I found write_canonical/1 but using numbervars/1,3,4 is preferred.

?- write_canonical(app(_29106, _29108, _29110)).
app(_,_,_)
true.

Bonus

Generating examples.

?- functor(Term,app,3),write_canonical(Term).
app(_,_,_)
Term = app(_29106, _29108, _29110).

Using with format/3

?- functor(Term,app,3),format('~k~n',[Term]).
app(_,_,_)
Term = app(_770, _772, _774).

When using with predicate that contains both the module and head.

If the module is not separated from the head the result may not be what is desired, e.g.

?- Pred = module:app(A,B,C),format('~k~n',[Pred]).
:(module,app(_,_,_))
Pred = module:app(A, B, C).

Simply deconstruct the predicate term into a module and head and format each separately, e.g.

?- Pred = module:app(A,B,C),Pred=Module:Head,format('~k:~k~n',[Module,Head]).
module:app(_,_,_)
Pred = module:app(A, B, C),
Module = module,
Head = app(A, B, C).