Article View: comp.lang.prolog
Article #1040Finding all solutions in Prolog
From: F0O
Date: Sat, 04 Aug 1990 15:25
Date: Sat, 04 Aug 1990 15:25
31 lines
1354 bytes
1354 bytes
I have a fairly simple question, but yet have never ran across any
book that explains it.
If you have a simple PDC prolog program like:
predicates
person(symbol)
clauses
person(jack).
person(jill).
person(mary).
and from the goal prompt type: person(X), you will get all 3 persons.
But if you have an internal goal like:
person(X), write(X),nl.
prolog will only find the first person. You would have to use the fail
predicate to force Prolog to find all solutions.
Why does Prolog only find the first solution on internal goals? I'd
think finding all solutions to a query would be more common than only
finding one.
I can see that only finding one solution and then using the fail
predicate gives you control over the search, however you could also use
the cut if you wanted to limit the search.
Am I missing something fundamental here?
[Tim]
Technical Details
Message-ID:
<90216.112514F0O@psuvm.psu.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!psuvax1!psuvm!f0oShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!psuvax1!psuvm!f0o From: F0O@psuvm.psu.edu Newsgroups: comp.lang.prolog Subject: Finding all solutions in Prolog Message-ID: <90216.112514F0O@psuvm.psu.edu> Date: 4 Aug 90 15:25:14 GMT Organization: Penn State University Lines: 31