1:- module(
    2  counter,
    3  [
    4    counter_create/1,    % -Counter
    5    counter_increment/1, % +Counter
    6    counter_increment/2, % +Counter, -Value
    7    counter_value/2      % +Counter, ?Value
    8  ]
    9).

A simple counter

*/

   15:- use_module(library(nb_ext)).
 counter_create(-Counter:compound) is det
   21counter_create(counter(0)).
 counter_increment(+Counter:compound) is det
 counter_increment(+Counter:compound, -Value:nonneg) is det
   28counter_increment(Counter) :-
   29  counter_increment(Counter, _).
   30
   31
   32counter_increment(Counter, Value) :-
   33  nb_increment(Counter, 1, Value).
 counter_value(+Counter:compound, +N:nonneg) is semidet
counter_value(+Counter:compound, -N:nonneg) is det
   40counter_value(counter(N), N)