counters.pl 362 Bytes
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3 4
:- module(
  counters,
  [
    set_counter/2,
Thierry Martinez's avatar
Thierry Martinez committed
5 6
    count/2,
    peek_count/2
Thierry Martinez's avatar
Thierry Martinez committed
7 8 9 10 11 12
  ]
).

set_counter(CounterName, InitialValue) :-
  nb_setval(CounterName, InitialValue).

Thierry Martinez's avatar
Thierry Martinez committed
13

Thierry Martinez's avatar
Thierry Martinez committed
14 15 16 17
count(CounterName, Value) :-
  nb_getval(CounterName, Value),
  NextValue is Value + 1,
  nb_setval(CounterName, NextValue).
Thierry Martinez's avatar
Thierry Martinez committed
18 19 20 21


peek_count(CounterName, Value) :-
  nb_getval(CounterName, Value).