call_count/4¶
call_count(? CallsMax, ? RetriesMax, ? CallsAndRetriesMax)*
Set call counters as timers. YAP will generate an exception if one of the instantiated call counters decreases to 0:
- CallsMax
throw the exception call_counter
when the counter calls
reaches 0;
- RetriesMax
throw the exception retry_counter
when the counter retries
reaches 0;
- CallsAndRetriesMax
throw the exception call_and_retry_counter
when the counter calls_and_retries
reaches 0.
YAP will ignore counters that are called with unbound arguments.
Next, we show a simple example of how to use call counters:
?- prolog_flag(call_counting,on), [-user]. l :- l. end_of_file. current_prolog_flag(call_counting,off).
yes
yes
?- catch ((call_count(10000,_,_),l),call_counter,format( "limit_exceeded.~n" ,[])).
limit_exceeded.
yes
Notice that we first compile the looping predicate l//00
with call_countingon
. Next, we @ref catchU2fU_3 "catch//3"3 to handle an exception when @ref U60UlU2fU_0 "l//0"0performs more than 10000 reductions.