# Attributed variables, reachability, garbage collection, debugging

**URL:** <https://swi-prolog.discourse.group/t/attributed-variables-reachability-garbage-collection-debugging/8946>\
**Category:** General\
**Created:** [April 17, 2025, 7:42pm UTC](https://swi-prolog.discourse.group/t/attributed-variables-reachability-garbage-collection-debugging/8946 "2025-04-17T19:42:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![z5h](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/z5h/32/5445_2.png) [@z5h](https://swi-prolog.discourse.group/u/z5h)\
**Post date:** [April 17, 2025, 7:42pm UTC](https://swi-prolog.discourse.group/t/attributed-variables-reachability-garbage-collection-debugging/8946/1 "2025-04-17T19:42:28Z")

</div>

I’d like a way to assert that a goal has left no residual variables.  
It seems that `call_residue_vars/2` isn’t what I want in that it (intentionally) disregards reachability.

So here:

```prolog
test_residue_vars(Vars) :-
    call_residue_vars(test_freeze(1, B), Vars).

test_freeze(A,B) :-
    freeze(X, (B = A)), !.

```

Even though X is not reachable in any way once we exit `test_freeze`, `call_residue_vars` will still report a nonempty list of residual variables.

Is there an (easy) way to implement:  
`no_residual_vars(Goal)` that succeeds only if there are no residual vars when Goal succeeds?

Is it correct to say:  
`no_residual(G) :- G, deterministic(D), !, D.`

(With the understanding that we literally claim ONLY that deterministic → no\_residual, but have not attempted to identify any other Goals where `no_residual(Goal)` is true)

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 17, 2025, 8:24pm UTC](https://swi-prolog.discourse.group/t/attributed-variables-reachability-garbage-collection-debugging/8946/2 "2025-04-17T20:24:41Z")

</div>

I don’t get it. Residual goals and determinism are pretty much orthogonal AFAIK. If you only want to consider reachable residuals, simply test that the answer does not contain any attributed variables using term\_attvars/2.
