Quick count of number of terms in the database?

I’m using: SWI-Prolog version 8.1.9.

Is there a way to get a quick count of all the terms in the database?

For example, let’s say I did the following:

assert(temp(dog)).
assert(temp(cat)).
assert(temp(bird)).

Is there something I can call that will give me the answer “3” for the query pattern (temp(_))?

aggregate_all(count, temp(_), Count).

or

aggregate(count, X^temp(X), Count).

The standard built-in predicate current_predicate/1 can be used to enumerate know predicates. The built-in predicate predicate_property/2 can be used to enumerate predicate properties, including the number of clauses. Combined with Peter suggestion, that should allow you to quickly compute exactly what you want.

4 Likes