# Question about message\_hook/3 and backtracking

**URL:** <https://swi-prolog.discourse.group/t/question-about-message-hook-3-and-backtracking/7565>\
**Category:** Predicate\
**Created:** [July 3, 2024, 2:44pm UTC](https://swi-prolog.discourse.group/t/question-about-message-hook-3-and-backtracking/7565 "2024-07-03T14:44:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christophe\_Rey](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@Christophe\_Rey](https://swi-prolog.discourse.group/u/Christophe_Rey)\
**Post date:** [July 3, 2024, 2:44pm UTC](https://swi-prolog.discourse.group/t/question-about-message-hook-3-and-backtracking/7565/1 "2024-07-03T14:44:20Z")

</div>

Hi,  
I do not understand the behaviour of the following program related to the interaction bewteen backtracking and the message\_hook/3 predicate.

```prolog
message_hook(_, informational, _).
message_hook(frame(_:Atom,trace(exit,_)), debug, _ ) :-
	writeln(message_hook(frame(_:Atom,trace(exit,_)), debug, _ )).
p(a).
p(b).
p(c).

```

Now with SWI 64bits, v9.2.5, I get:

```prolog
2 ?- p(X).
X = a ;
X = b ;
X = c.

3 ?- trace(p/1,+exit), p(X), trace(p/1,-exit).
message_hook(frame(_5174:p(a),trace(exit,_5182)),debug,_5164)
X = a ;
message_hook(frame(_7180:p(b),trace(exit,_7188)),debug,_7170)
message_hook(frame(_7534:p(c),trace(exit,_7542)),debug,_7524)
false.

```

I understand that before displaying `X = a`, `trace(p/1,-exit)` has been successfully executed. But, when backtracking on `p(X)`, why does it still launch message\_hook/3 and doesn’t he display `X = b` and `X = c` ?

Thanks in advance
