# Library(prolog\_coverage) - working with predicates generated via persistent/1

**URL:** https://swi-prolog.discourse.group/t/library-prolog-coverage-working-with-predicates-generated-via-persistent-1/9427
**Category:** Help!
**Created:** [December 11, 2025, 3:54pm UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-working-with-predicates-generated-via-persistent-1/9427 "2025-12-11T15:54:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)
#### Post date: [December 11, 2025, 3:54pm UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-working-with-predicates-generated-via-persistent-1/9427/1 "2025-12-11T15:54:01Z")

</div>

$ swipl --version  
SWI-Prolog version 10.0.0 for x64-win64

Using [library(prolog\_coverage)](https://www.swi-prolog.org/pldoc/man?section=prologcoverage) on a module that uses [library(persistency)](https://www.swi-prolog.org/pldoc/man?section=persistency).

For code coverage for persistent/1 was able to increase the code coverage by adding tests for the dynamicly created four predicates resulting in this

```prolog
   90 ### ⮰
      ++20 ⮰
      ++4,727 ⮰
      ++21,486 ⮰
      +55,950-20 :- persistent(pred_def(name:atom, arity:integer, module:atom, file:atom, line:integer)).

```

There is now just the one remaining `###` that I have no idea of what it could be.

Any ideas? Is it a predicate, an artifact of code coverage that can be removed, other?

Any ideas on how to get a line in the cov report to show what it could be?

* * *

Gave Claude the links to the SWI-Prolog library code on GitHub and noted the relevant files in the project and Claude thinks

```prolog
   90 ### ⮰ ← The directive itself: never "executed"
      ++20 ⮰ ← Generated predicate variant 1
      ++4,727 ⮰ ← Generated predicate variant 2
      ++21,486 ⮰ ← Generated predicate variant 3
      +55,950-20 ← Generated predicate variant 4
             :- persistent(pred_def(name:atom, arity:integer, module:atom, file:atom, line:i

```

If that is true would like to find a way to remove such lines from the cov report so that the report shows 100% coverage for the module. Currently Claude will search for `###` lines and thus it is like having a wrench thrown into the clock works.

---

<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: [December 12, 2025, 12:41pm UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-working-with-predicates-generated-via-persistent-1/9427/3 "2025-12-12T12:41:29Z")

</div>

> [@EricGT](#):
>
> ` 90 ### ⮰ ← The directive itself: never "executed"`

I don’t think that is true. The directive is term-expanded to a set of predicates. I suspect one of them is not used by your tests. Which one is a bit hard to tell. Ideally the system should provide better feedback for this, but I’m not sure how.

I’d create a module with only this declaration and list the content so you can understand what is going on.

---

<div class="post-metadata">

### Author: ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)
#### Post date: [December 13, 2025, 8:18pm UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-working-with-predicates-generated-via-persistent-1/9427/4 "2025-12-13T20:18:26Z")

</div>

> [@jan](#):
>
> I suspect one of them is not used by your tests.

Result confirms that is true.

* * *

* * *

There are five, not four generated predicates from persistent/1.

From documentation

> The [persistent/1](https://www.swi-prolog.org/pldoc/man?predicate=persistent/1) expands each declaration into four predicates:
> 
> - `name(Arg, ...)`
> - `assert_name(Arg, ...)`
> - `retract_name(Arg, ...)`
> - `retractall_name(Arg, ...)`

using

` :- persistent(pred_def(name:atom, arity:integer, module:atom, file:atom, line:integer)).`

the following are generated

| Generated predicate | type |
| --- | --- |
| pred\_def/5 | base |
| assert\_pred\_def/5 | assert\_ |
| asserta\_pred\_def/5 | asserta\_ |
| retract\_pred\_def/5 | retract\_ |
| retractall\_pred\_def/5 | retractall\_ |

* * *

```prolog
   90 ++21,486 ⮰
      ++20 ⮰
      ++4,987 ⮰
      +55,950-20 ⮰
      ++20 :- persistent(pred_def(name:atom, arity:integer, module:atom, file:atom, line:integer)).

```

* * *

Jan updated the SWI-Prolog documentation for library(persistency)

> <https://github.com/SWI-Prolog/swipl-devel/commit/a93fda5dd9d5c923d046b37462c2e51e1df3705c>

---

<div class="post-metadata">

### Author: ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)
#### Post date: [December 13, 2025, 8:42pm UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-working-with-predicates-generated-via-persistent-1/9427/5 "2025-12-13T20:42:54Z")

</div>

> [@jan](#):
>
> I’d create a module with only this declaration and list the content so you can understand what is going on.

Filename: `test_persistency.pl`

```prolog
% Minimal Fixture: Single persistent/1 directive with arity 1
% Purpose: Isolate coverage behavior for one persistent declaration
%
% This module tests the simplest case:
% - One persistent/1 directive
% - Arity 1 (single argument)
% - Generates 5 predicates: foo/1, assert_foo/1, asserta_foo/1, retract_foo/1, retractall_foo/1

:- module(test_persistency, []).

:- use_module(library(persistency)).

% Single persistent declaration - should generate exactly 5 predicates
:- persistent(foo(value:any)).

```

```prolog
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 10.0.0)

4 ?- [test_persitency].
true.

5 ?- findall(Name/Arity, (current_predicate(test_persistency:Name/Arity), sub_atom(Name, _, _, _, foo)), Preds),sort(Preds, 
SortedPreds),forall(member(Name/Arity, SortedPreds), format('~w/~w~n', [Name, Arity])).
assert_foo/1
asserta_foo/1
foo/1
retract_foo/1
retractall_foo/1
Preds = [retract_foo/1, retractall_foo/1, foo/1, asserta_foo/1, assert_foo/1],
SortedPreds = [assert_foo/1, asserta_foo/1, foo/1, retract_foo/1, retractall_foo/1].

```

---

<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: [December 15, 2025, 10:05am UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-working-with-predicates-generated-via-persistent-1/9427/6 "2025-12-15T10:05:36Z")

</div>

> [@EricGT](#):
>
> asserta\_pred\_def/5 asserta\_

Added to the docs.
