Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!wuarchive!decwrl!shelby!neon!feldman From: feldman@Neon.Stanford.EDU (Todd J. Feldman) Newsgroups: comp.lang.prolog Subject: Re: elementary problem (I hope) Message-ID: <1990Mar10.120125.12992@Neon.Stanford.EDU> Date: 10 Mar 90 12:01:25 GMT References: <1990Mar9.095655.4191@bath.ac.uk> Sender: Todd J. Feldman(feldman@neon.stanford.edu) Organization: Computer Science Department, Stanford University Lines: 29 In article <1990Mar9.095655.4191@bath.ac.uk> ccsdgdc@gdr.bath.ac.uk (Douglas Clark) writes: > >A user has been asking me how to write synonyms in Prolog. Being ignorant >I have no idea. It is obvious why the natural > >father(X):-male(X). >male(X):-father(X). >father(fred). > >fails. But I cannot find a substute that works. Some way of eliminating >the repetitive backtracking. Help would be appreciated. How about: father(X):- not(tried(male(X))), assert(tried(male(X))), male(X). male(X):- not(tried(father(X))), assert(tried(father(X))), father(X). if you store any 'male' or 'father' facts, they will be detected, and any infinite recursion will be prevented by the 'tried' facts. Of course, you'd need to be sure to clean up these 'tried' facts when you're done. Todd