|
This may help : - go/2 takes G and T. It copies G to G1 (no shared variable), calls G1 (hence G) and if success, next/3 will decide. - next/3 retries G (hence G1) but if there is a solution different from the first call (in go/2), then cuts and conludes on a failure. Otherwise, next/3 takes the only solution into T. - more_than_one is here to write some blabla. Other 'write(...)' are also there for a trace. Try it with : go(p0(X), T). go(p1(X), T). go(p2(X), T). go(p3(X), T). Only go(p0(X), T). succeeds. Others will write things but fail. PS : there is no try with an nonexistent predicat; you may set the appropriate flag and try with that case also. Cheers Alex ------------------ go(G, T) :- copy_term(G,G1), call(G1), next(G,G1,T). next(G,G1,T) :- G, G \== G1, !, more_than_one(G,G1,T). next(_G,G1,T) :- T=G1, write('case one solution\n'). % succeed, only one solution. more_than_one(_G,_G1,_T) :- write('case with more than one solution \n'), fail. % ex for G with 0, 1 and more solutions. p0(_):- fail. % zero solution for p0 p1(1). % one solution predicate p2(1). % Two solutions for p2 p2(2). p3(1). % 3 (or more) soultions p3(2). p3(3).------------------------ michel levy a écrit : Could you help to write this program : -- Aleksander S. Saidi Maître de Conférences Ecole Centrale de Lyon Département Mathématiques-Informatique Mél : [EMAIL PROTECTED] Tél : 04.72.18.65.30, Fax : 04.78.33.16.15 |
begin:vcard fn:A-S Saidi n:A-S Saidi;A-S org:Ecole Centrale de Lyon;LIRIS- UMR 5205 CNRS email;internet:[EMAIL PROTECTED] title;quoted-printable:Ma=C3=AEtre de Conf=C3=A9rences tel;work:04 72 18 65 30 tel;fax:04 78 33 16 15 x-mozilla-html:TRUE version:2.1 end:vcard
_______________________________________________ Users-prolog mailing list [email protected] http://lists.gnu.org/mailman/listinfo/users-prolog
