From pascal@rz.hu-berlin.de  Thu Feb 17 16:11:38 2000
Received: from suncom.rz.hu-berlin.de (suncom.rz.hu-berlin.de [141.20.1.31])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA07997
	for <prolog@swi.psy.uva.nl>; Thu, 17 Feb 2000 16:11:38 +0100 (MET)
Received: from localhost.rz.hu-berlin.de (pascal@ppp196-162.rz.hu-berlin.de [141.20.196.162])
	by suncom.rz.hu-berlin.de (8.9.3/8.9.3) with ESMTP id QAA25094
	for <prolog@swi.psy.uva.nl>; Thu, 17 Feb 2000 16:11:11 +0100 (MET)
Received: (from pascal@localhost)
	by localhost (8.8.8/8.8.8/Debian/GNU) id QAA14560;
	Thu, 17 Feb 2000 16:12:19 +0100
Date: Thu, 17 Feb 2000 15:12:18 +0000 (GMT)
From: Pascal Vaillant <Pascal.Vaillant@rz.hu-berlin.de>
To: prolog@swi.psy.uva.nl
Subject: Re: timed goal in SWI-Prolog
Message-ID: <Pine.LNX.4.05.10002171511320.14557-100000@ppp196-162.rz.hu-berlin.de>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from QUOTED-PRINTABLE to 8bit by swi.psy.uva.nl id QAA07997



> 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

