[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: determinism

From: Daniel Diaz
Subject: Re: determinism
Date: Mon, 12 Feb 2007 18:11:56 +0100
User-agent: Thunderbird (X11/20061107)

michel levy a écrit :
> Could you help to write this program :
> det(T,G) succeeds if and only if G succeeds once and only once and give
> the T answer.
> 1) I don't want the solution below by findall, because I want to try at
> most two back tracks on G.
> det(T,G) :- findall(T,G,L),length(L,1)
> 2) I know already call_det but it's not the solution because G can have
> choice points, but only one answer.

You can do it using a global variable to count solutions. Stop when the
second is reached.

det(Goal) :-

det(_) :-
        g_read(det_count, 1).

det1(Goal) :-
        g_assign(det_count, 0),
        g_inc(det_count, Count), % increment and return the counter
        Count = 2,      % cut if 2nd solution is reached (else fail)

Hope this helps

Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]