Re: delay clauses

From: Joachim Schimpf <js10_at_icparc.ic.ac.uk>
Date: Tue 09 Mar 1999 06:22:32 PM GMT
Message-ID: <36E566E8.2781E494@icparc.ic.ac.uk>
Joerg Harm wrote:
> ...
> But the goal
> :- integers(2,L), filter(2,L,[N|R]), R = [M|S].
> results in the error message:
> instantiation fault in mod(N, 2, _262)
> 
> The manual says that the delayed integers goal is woken before the
> conditional is executed. Therefore, N should be instantiated to an
> integer.



This has to do with goal priorities.

In Eclipse, goals run with a priority from 1 (most urgent)
to 12 (least urgent). The initial goal you call from the
top-level runs with priority 12. When a delayed goal wakes
up, it is woken with a certain priority, and this priority
decides whether it interrupts the currently executing goal
or not.

Delay-clauses unfortunately don't allow you to specify the
priority (they were invented before we introduced priorities...),
so goals delayed by delay-clauses are always woken with priority 2.
What happens in your example is that a filter-goal (which was
itself woken and is running with priority 2) wakes an integers-goal
(which has also priority 2). Because the integers-goal does not
have higher priority than the currently executing filter-goal,
it does not interrupt it, but is queued and will run after filter
finishes.

If you replace the delay clause

    delay filter(_, Li, Lo) if var(Li), var(Lo).

with the following clause

    filter(P, Li, Lo)  :- var(Li), var(Lo), !,
        suspend(filter(P, Li, Lo), 3, [Li,Lo]->inst).

you can specify the waking priority in the suspend-call (here 3).
Then the program works as expected:


[eclipse 4]: integers(2,L), filter(2,L,[N|R]), R = [M|S].

L = [2, 3, 4, 5|LI]
N = 3
R = [5|S]
M = 5
S = S

Delayed goals:
        integers(6, LI)
        filter(2, LI, S)
yes.



------------------------------------------------------------------------
 Joachim Schimpf                /               phone: +44 171 594 8187
 IC-Parc, Imperial College     /              mailto:J.Schimpf@ic.ac.uk
 London SW7 2AZ, UK           /      http://www.icparc.ic.ac.uk/eclipse
Received on Tue Mar 9 18:25:45 1999

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:04 PM GMT GMT