Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a list out of rules

Status
Not open for further replies.

bewmar

Programmer
Nov 27, 2008
1
CA
I need to form a list of all members of an object that are defined by rules. Example:

has(face,eyes,2).
has(eyes,pupil,1).

I want to be able to extract the information in such a way that a predicate list_part would return all the attributes a certain object has. In the above example list_part(face,X) should return X = [eyes, pupil].

I've been going in circles on this one, any help is greatly appreciated.
 
If you have SWI-Prolog, take a look at bagof/setof.
 
well it's easy. Just do

has(face,eyes,2).
has(eyes,pupil,1).

list_part(X,Y,C):- findall(X,L,has(Y,L),C).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top