Subject: Re: timed goal in SWI-Prolog

From: Pascal Vaillant <[email-masked]>
Date: Thu, 17 Feb 2000 15:12:18 +0000 (GMT)

> Hi. Is there any way to try a goal for a certain amount of time and
> fail it when it does not return when the time is up. I mean something
> like time(X,T): it returns "yes" if X succeeds in less than T seconds,
> and "no" if either the goal X does not return in T seconds or X returns
> "no".
> 

Yes : you can catch an interruption signal like "SIGALRM" by
calling your Goal not simply by :

Goal.

but by :

catch(Goal,error(signal(alrm,_),_),Goal_To_Execute_On_Signal).

(The signal SIGALRM itself is programmed by default to throw
an exception if it is received) ;

and sending in parallel some counter which will send the alarm
after a given time.

There is an example of this in section 3.9 of the SWI-Prolog
manual. It programs the counter in C, but if you don't want to
use C, you can also do it with a Unix shell.

Regards,

Pascal Vaillant
Berlin

--
Pascal Vaillant                                Jägerstraße 10/11
Humboldt Universität zu Berlin                 10117 Berlin (Allemagne)
Lehstuhl Computerlinguistik                    Tel: (+49/30) 20 19 25 54