Re: determinism
Daniel Diaz <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.general |
|---|---|
| Message-ID | <[email protected]> |
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) :- det1(Goal). det(_) :- g_read(det_count, 1). det1(Goal) :- g_assign(det_count, 0), call(Goal), g_inc(det_count, Count), % increment and return the counter Count = 2, % cut if 2nd solution is reached (else fail) !, 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.