Counting asserted facts

Hello,

Is there an efficient way to know how many facts in total were asserted into the Prolog fact store. For example – suppose I am asserting a number of fact types:

fact_type_1(a).
fact_type_2(a,b).

And then know how many fact_type_1/1 and fact_type_2/2, there are.

I am interested in all facts not the result of a goal / query with constraints.

Can this be done without actually retrieving each one of them and counting them?

Or, do i need to actually keep track of their count, e.g.

add_fact_type_1 :-
fact_type_1_count(N),
retractall(fact_type_1_count(N)),
N1 is N + 1,
assert(fact_type_1_count(N1)).

thank you,

Dan

See https://www.swi-prolog.org/pldoc/doc_for?object=predicate_property/2

Great. Thanks!

Would have never found this!

number_of_clauses (ClauseCount)

Unify ClauseCount to the number of clauses associated with the predicate. Fails for foreign predicates.

Daniel